Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel 15 posts 107 karma points
    Dec 10, 2013 @ 02:33
    Daniel
    0

    Missing MVC Reference?

    Im working on using the UmbracoHelper class to query some nodes using .Where(), On build I am getting :

    Error   27  The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
    

    Not really sure where to go from here, I have MVC 3 and MVC 4 installed. Not sure if it something I am doing wrong with the Where statement or if it really is a missing reference. Builds fine without the where.

                var helper = new UmbracoHelper(UmbracoContext.Current);
                var years = helper.TypedContent(1077).Children.Where(x => x.Id > 15);
    
                foreach (var x in years)
                {
                    response += x.Name;
                }
    
  • Per Ploug 865 posts 3491 karma points MVP admin
    Dec 10, 2013 @ 09:46
    Per Ploug
    0

    in your project references, do you have system.web.mvc listed? also, .net 4.5 is required.

  • Jesper 8 posts 51 karma points
    Jul 01, 2014 @ 14:00
    Jesper
    0

    I experienced the same issue (using .net 4.5). I have a repository class (separate project) that takes an int "id" and returns a list of names (as a simple example).

            public IEnumerable<string> GetAllNewsItemNames(int id)
            {
                var helper = new UmbracoHelper(UmbracoContext.Current);
                var newsContainer = helper.TypedContent(id);
                return newsContainer.Children.Select(x => x.Name);
            }

    When I use the Linq Select() statement I get the error:

    Error1The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.D:\Dev\MyProject\MyProject.Repository\Umbraco\NewsRepository.cs2413MyProject.Repository
    Error2The type 'System.Web.Http.ApiController' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.D:\Dev\MyProject\MyProject.Repository\Umbraco\NewsRepository.cs2413MyProject.Repository

    If I only use foreach statement the error disappears:

    public IEnumerable<string> GetAllNewsItemNames(int id)
    {
    var helper = new UmbracoHelper(UmbracoContext.Current);
    var newsContainer = helper.TypedContent(id);
    var names = new List<string>();
    foreach (var newsItem in newsContainer.Children)
            {
    names.Add(newsItem.Name);
    }
            return names;

    I'd rather not have references to System.Web in my repository project in order to keep seperation of concerns. Any clues on this?

Please Sign in or register to post replies

Write your reply to:

Draft