我试图编写一个网页,它将根据与该项目相关的严重性级别来切换项目的颜色。我在mscorlib中使用System.Diagnostics.Tracing.EventLevel枚举。
当我试图编译此页面时,会得到一个编译错误: error CS0234:名称空间'System.Diagnostics‘中不存在类型或名称空间名称’System.Diagnostics‘(您是否缺少程序集引用?)
代码本身在.cshtml文件中看起来很好,intellisense可以检测名称空间和类型,并适当地完成所有内容,只是无法编译。如果我在剃刀视图中的类型上按下F12,它会带我到mscorlib信息。该网站项目并不缺少对mscorlib的引用,因为这是默认情况下所有此类项目都包含的默认库(VS告诉我,当我尝试将它“添加”到项目引用文件夹时)。我做错了什么?
@model NMCOnlineServices.Website.Areas.HEI.Models.EditRecordViewModel
@using NMCOnlineServices.Website.Areas.HEI.Extensions
@functions{
public String GetColour(System.Diagnostics.Tracing.EventLevel level)
{
switch (level)
{
case System.Diagnostics.Tracing.EventLevel.Critical:
case System.Diagnostics.Tracing.EventLevel.Error:
return "Red";
case System.Diagnostics.Tracing.EventLevel.Warning:
return "Amber";
default:
return "Black";
}
}
}
//More view stuff here, compiler bombs out on the GetColour() declaration 发布于 2015-03-12 16:37:14
所有正在使用的项目都以.NET 4.5为目标。该项目的总体web.config包含以下一行:
<compilation debug="true" targetFramework="4.0">解决方法是将其更改为:
<compilation debug="true" targetFramework="4.5">https://stackoverflow.com/questions/29014328
复制相似问题