代码之家  ›  专栏  ›  技术社区  ›  madcapnmckay

未能在App_代码中编译Linq方法

  •  0
  • madcapnmckay  · 技术社区  · 16 年前

    我搔了好长时间的头。我确信它确实很容易修复,但我看不出来。

    我在App_代码中有一个类,它使用了一点Linq。

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

    我在本地开发了这个,一切都很好。当我传输到承载相同类的IIS时,编译失败。我收到:

    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?)
    

    我确认虚拟目录正在运行.NET2.0。我还确认在web.config中加载了正确的程序集。

    <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>
    

    我也尝试过在web.config中添加名称空间指令,但没有成功。有人能想出别的办法吗?

    4 回复  |  直到 16 年前
        1
  •  0
  •   Gregory    16 年前

        2
  •  0
  •   SLaks    16 年前

    添加 using System.Linq; .cs 文件

    另外,确保 SiteMapWrapper 工具 IEnumerable<T> .

    编辑 :我没有注意到它在本地机器上工作。
    确保服务器具有所有依赖程序集的正确版本。

        3
  •  0
  •   RickNZ    16 年前

    LINQ实际上需要.NET3.0(3.5更好),而不是2.0。确保AppPool配置正确。

        4
  •  0
  •   Mohamed ElHamamsy    10 年前

    改变 构建操作 中的.cs文件的属性 编撰 .

    See this article 更多信息。