ASP.NET MVC 2 + LINQ to SQL - CS0012 Compilation Error
Asked Answered
C

1

16

In my database schema each forum has a category and categories can have many forums. I'm trying to list categories and their respective forums with the following code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Index</h2>
    <% foreach (GameSite.Models.Category category in (IEnumerable)ViewData["Categories"])
       { %>
       <%= category.Name %>
       <% foreach (GameSite.Models.Forum forum in (IEnumerable)category.Forums)
          { %>
          <%= forum.Name %>
       <% } %>
    <% } %>
</asp:Content>

When this is run I get the following error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0012: The type 'System.Data.Linq.EntitySet`1<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'.

Source Error:    
Line 11:        { %>
Line 12:        <%= category.Name %>
Line 13:        <% foreach (GameSite.Models.Forum forum in (IEnumerable)category.Forums)
Line 14:           { %>
Line 15:           <%= forum.Name %>

I can confirm that System.Data.Linq is being referenced in my project.

Any ideas?

Carioca answered 15/4, 2010 at 1:33 Comment(2)
Are you sure you are referencing the 4.0 of System.Data.Linq version rather than the 3.5 version? Did you check the web.config file?Bassesalpes
Yes, I'm referencing the 4.0 version. What do you want me to look for in the web.config file? I don't see System.Data.Linq mentioned anywhere.Carioca
C
43

Adding this to the web.config file did the trick.

    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Carioca answered 15/4, 2010 at 1:55 Comment(5)
What part of the web.config file do I need to add this?Quadrifid
I've forgotten now, so maybe someone else can help you more. Only advice I can offer is to look for other <add assembly> lines and chuck it in there.Carioca
<configuration> <system.web> <compilation targetFramework="4.0"> <assemblies> <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </assemblies> </compilation> </system.web> </configuration>Heptane
I'm having the same problem. In MVC 4, you don't need to add the assemblies, and it actually throws an error when you try to do so. I'm getting this error on only one page. All my other pages are using LINQ with no problems.Failure
Clicking on the reference and setting copy local= true fixed it for me. It was breaking in the Views, in the controllers it worked find. Very strange. MVC4 - I also added the namesapce into the views web.configHerring

© 2022 - 2024 — McMap. All rights reserved.