开发者

Failure to compile Linq Method in App_Code

I've been scratching my head for what seems like ages. I'm sure its really simple to fix but I can't see it.

I have a class in App_Code that uses a bit of Linq.

var siteMap = SiteMapWrapper.BuildSiteMap(true);
var currentTopLevelParent = siteMap.Single(s => s.IsActive);
if (currentTopLevelParent != null)

I've developed this locally and all works fine. When I transfer to IIS hosting the same class fails to compile. I receive:

does not contain a definition for 'Single' and no extension method 'Single' 
accepting a  first argument of type 'SiteMapWrapper' could be found (are you 
missing a using directive or an assembly reference?)

I confirmed that the virtual dir is running .NET 2.0 as it should. I also confirmed that the correct assemblies are being loaded in the web.c开发者_StackOverflow社区onfig.

<compilation debug="true">
  <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  </assemblies>
</compilation>

I've tried adding namespaces directives in web.config also but no luck. Can anyone think of anything else to try?

Many thanks.


I think you will find that the server does not have 3.5 installed.


Add using System.Linq; to the top of the .cs file.

Also, make sure that SiteMapWrapper implements IEnumerable<T>.

EDIT: I didn't notice that it works on the local machine.
Make sure that the server has the correct versions of all of the dependent assemblies.


LINQ actually requires .NET 3.0 (3.5 is better), not 2.0. Make sure the AppPool is configured appropriately.


Change the Build Action Property of your .cs file from Content to Compile.

See this article for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜