【问题标题】:The type or namespace name 'Stack' could not be found (only with .NET 4.0)找不到类型或命名空间名称“堆栈”(仅适用于 .NET 4.0)
【发布时间】:2012-02-29 02:06:52
【问题描述】:

编译这个程序时出现错误:

using System;
using System.Collections.Generic;

static class main {
    public static void Main() {
        Stack<int> a;
    }
};

使用这个 cmd:

C:\Users\tomc\Desktop\l&gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc test.cs

我收到此错误:

test.cs(12,3): 错误 CS0246: 类型或命名空间名称“堆栈”不能是 找到(您是否缺少 using 指令或程序集引用?)

但是,当使用此命令时,它构建得很好: C:\Users\tomc\Desktop\l&gt;C:\Windows\Microsoft.NET\Framework64\v3.5\csc test.cs

堆栈是否已从 .NET 4 中删除?我在 MSDN 上找不到任何迹象。

【问题讨论】:

  • “堆栈是否已从 .NET 4 中删除?”没有。
  • 您提供的示例可以在 Visual Studio 和命令行中正常编译。
  • 如果您想比较@YuriyGuts 提到的文件,这是我安装的文件:pastebin.com/hB5KhqcH
  • @Stijn 我什至没有那个文件:S 在构建之前我必须修改你的一点。我的现在看起来像这样pastebin.com/ifCL0AbT
  • 我的第一个答案已转换为评论。我将尝试扩展我的答案并再次发布以防其他人遇到此问题。

标签: c# .net .net-4.0


【解决方案1】:

C# 编译器有一个默认的“配置”文件(称为response file),位于 .NET Framework 安装目录 (c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.rsp) 中。该响应文件只是一个文本文件,其中包含一组编译程序时默认传递的编译器命令行开关。除了默认文件之外,您还可以指定自己的文件(请参阅上面的链接)。

在您的情况下,此文件可能丢失或损坏。您可以检查那里是否存在对核心库的引用。例如,这是我机器上的 csc.rsp 文件:

# This file contains command-line options that the C#
# command line compiler (CSC) will process as part
# of every compilation, unless the "/noconfig" option
# is specified. 

# Reference the common Framework libraries
/r:Accessibility.dll
/r:Microsoft.CSharp.dll
/r:System.Configuration.dll
/r:System.Configuration.Install.dll
/r:System.Core.dll
/r:System.Data.dll
/r:System.Data.DataSetExtensions.dll
/r:System.Data.Linq.dll
/r:System.Data.OracleClient.dll
/r:System.Deployment.dll
/r:System.Design.dll
/r:System.DirectoryServices.dll
/r:System.dll
/r:System.Drawing.Design.dll
/r:System.Drawing.dll
/r:System.EnterpriseServices.dll
/r:System.Management.dll
/r:System.Messaging.dll
/r:System.Runtime.Remoting.dll
/r:System.Runtime.Serialization.dll
/r:System.Runtime.Serialization.Formatters.Soap.dll
/r:System.Security.dll
/r:System.ServiceModel.dll
/r:System.ServiceModel.Web.dll
/r:System.ServiceProcess.dll
/r:System.Transactions.dll
/r:System.Web.dll
/r:System.Web.Extensions.Design.dll
/r:System.Web.Extensions.dll
/r:System.Web.Mobile.dll
/r:System.Web.RegularExpressions.dll
/r:System.Web.Services.dll
/r:System.Windows.Forms.Dll
/r:System.Workflow.Activities.dll
/r:System.Workflow.ComponentModel.dll
/r:System.Workflow.Runtime.dll
/r:System.Xml.dll
/r:System.Xml.Linq.dll

【讨论】:

  • 在我的情况下,我也面临同样的错误,但文件存在于它应该存在的位置并且它没有损坏。还有什么问题?
猜你喜欢
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-12
  • 2011-05-13
  • 2013-03-25
  • 2012-06-19
相关资源
最近更新 更多