System.Linq namespace missing even with reference to System.Core.Dll
Asked Answered
I

2

6

When I open up a Asp Net web site of mine in Visual Studio 2010 the properties say "Target Framework 3.5", however when I try to using the Linq namespace the compiler complains about it.

"The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)"

"The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)"

I manually referenced some dll's to fix my problem, but still no success.

<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

Help? :-)

Interrupt answered 30/9, 2010 at 10:38 Comment(0)
M
5

If you can't even use var, that suggests it's not even using the right version of the C# compiler. (You should be able to use var even when targeting .NET 2.0, so long as you're using the C# 3 or C# 4 compiler.) I would concentrate on getting that working first before anything else.

Is it possible that you're running on IIS but don't have that configured appropriately? It might be worth looking at your website configuration around that side of things, and possibly rerunning aspnet_regiis.

Matildematin answered 30/9, 2010 at 10:42 Comment(3)
Thanks for pointing me in the right direction - when I'm looking at the YSOD and expanding Show Detailed Compiler output this is what I get: Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.4016 for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 --- but I hesitate running aspnet_regiis, how can I be sure I'm not breaking stuff? It's a live server.Interrupt
...learning new stuff here... there's a lot of 2.0-references in the site's IIS .Net compilation section Assemblies. (Not found in the web.config).Interrupt
Needed to follow the wisdom of Scott Hanselman hanselman.com/blog/… adding some lines to the <system.codedom> section. Works now, great!Interrupt
D
2

I just fixed a similar issue adding a targetFramework="4.0" attribute to the compilation element in web.config

The modified relevant fragment is:

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  </assemblies>
</compilation>
Dissension answered 14/8, 2014 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.