locked
Views Wont Compile After Upgrade to .NET 4.0 RRS feed

  • Question

  • User2064935679 posted

    I have upgraded my project from .NET 3.5 to 4.0 and my views will no longer compile.

    I have a data layer that is a Linq to SQL data context in an assembly.

    My problem is when I pass in an entity to the model of my view and then try an enumerate a property that is an entity set of foreign key values I get a compilation error of

    The type 'System.Data.Linq.EntitySet`1<T0></T0><T0></T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    I have added a reference to the project for System.Data.Linq and I can enumerate the entity sets in my controllers, it is just when trying to do it in a view I get the issue.

    This works fine in a .NET 3.5 project and thought I may have upgraded incorrectly but I get the same issue if I start a new project from scratch.

    What do I have to do to allow my views to enumerate the entity sets?<T0></T0><T0></T0>

    Tuesday, April 13, 2010 2:29 AM

Answers

  • User401360897 posted

    try to Add System.Data.Linq in web.config

    http://forums.asp.net/t/1546728.aspx


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 11:14 PM

All replies

  • User654067467 posted

    I have not yet had the pleasure of being allowed to upgrade to .NET 4.0 but if you have the problem only in your views you may try to add <%@ Import Namespace="System.Data.Linq"%> in the view and see if it works... I'm sorry that I cannot verify wheter this works but it's worth a try. Please let me know if this helped so I can keep this in mind when updating the ongoing project to .NET 4.0.

    Tuesday, April 13, 2010 4:23 AM
  • User2064935679 posted

    If I try and import the name space I get

    Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

    I cannot be the only one who passes Linq to SQL generated objects into strongly typed views. This is a major show stopper for me as many of my views use this.


    Action Works.

            public ActionResult Index()
            {
    			DataClasses1DataContext dc = new DataClasses1DataContext(ConfigurationManager.ConnectionStrings["CVRSConnectionString"].ToString());
    			Plant plant = dc.Plants.Single(p => p.Id == 1);
    			foreach (PlantArea plantArea in plant.PlantAreas)
    			{
    			}
                return View(plant);
            }

    View fails

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Plant>" %>

    <%@ Import Namespace="ClassLibrary1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

        <title>ViewPage1</title>

    </head>

    <body>

        <div>

    <% foreach (PlantArea plantArea in Model.PlantAreas) { %>

    <%: plantArea.Name %><br />

    <% } %>

        </div>

    </body>

    </html>

            public ActionResult Index()
            {
    DataClasses1DataContext dc = new DataClasses1DataContext(ConfigurationManager.ConnectionStrings["CVRSConnectionString"].ToString());
    Plant plant = dc.Plants.Single(p => p.Id == 1);
    foreach (PlantArea plantArea in plant.PlantAreas)
    {
    }
                return View(plant);
            
    Tuesday, April 13, 2010 7:17 PM
  • User-1526326474 posted

    This one is killing me too! It worked in VS2010 RC with .NET 4.0 RC, but when I upgraded the two to RTM today, I started getting this exact same error.

    Tuesday, April 13, 2010 9:47 PM
  • User-1526326474 posted

    Are you using PLINQO?

    Tuesday, April 13, 2010 10:14 PM
  • User401360897 posted

    Just Right Click on Plant class and then Go to Defination then check the namespace of Plant and PllantArea and then put it in Import tag

    Tuesday, April 13, 2010 10:59 PM
  • User2064935679 posted

    No I am not using PLINQO. I am using the Visual Studio Linq to SQL designer.

    Tuesday, April 13, 2010 11:03 PM
  • User2064935679 posted

    The ClassLibrary1 name space is already being imported, it is not an issue with the data contexts assembly name space but with System.Data.Linq.

    Tuesday, April 13, 2010 11:04 PM
  • User401360897 posted

    try to Add System.Data.Linq in web.config

    http://forums.asp.net/t/1546728.aspx


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 11:14 PM
  • User2064935679 posted

    Thank you, you have saved me from pulling my hair out.

    Updated web.config to add the line

    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089" />


    to the system.web -> compilation -> assemblies section.

    For some reason a 3.5 project adds this line but a 4.0 project does not.

    Tuesday, April 13, 2010 11:23 PM
  • User401360897 posted

    For some reason a 3.5 project adds this line but a 4.0 project does not.

    It is also new informtaion for me

    Tuesday, April 13, 2010 11:44 PM
  • User2064935679 posted

    Maybe this is a push away from Linq to SQL as I tried it with the entities framework and in 4.0 project and it adds the line

    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    to the web.config when you add an entity data model to your project.

    So why would they change a 4.0 project to no do the same thing a 3.5 project does?

    Wednesday, April 14, 2010 12:00 AM
  • User401360897 posted

    So why would they change a 4.0 project to no do the same thing a 3.5 project does?

    I think this is because [link=http://weblogs.asp.net/scottgu/archive/2009/08/25/clean-web-config-files-vs-2010-and-net-4-0-series.aspx]clean web.config[/link]

    I remembered that when 3.5 released which is built on top of ASP.NET 2.0 and ASP.NET Team Members support the same ASP.NET application with some additional assemblies.

    Since Views are compiled in different assemlies than application, this may be the reason of needed this reference in Views

    Wednesday, April 14, 2010 12:43 AM