简体   繁体   中英

Razor not compiling System.Diagnostics.Tracing.EventLevel

I'm attempting to write a web page that will switch the colour of an item depending on the severity level associated with that item. I'm using the System.Diagnostics.Tracing.EventLevel enumeration in the mscorlib DLL.

When I try to compile this page, I get a compilation error: error CS0234: The type or namespace name 'Tracing' does not exist in the namespace 'System.Diagnostics' (are you missing an assembly reference?)

The code itself looks fine in the .cshtml file, intellisense can detect the namespace and the types and completes everything appropriately, it just won't compile. If I press F12 on the type in the razor view it takes me to the mscorlib DLL info. The website project isn't missing a reference to mscorlib because that is a default library that all such projects have in by default (VS told me this when I tried to 'add' it to the project references folder). What am I doing wrong?

@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 

All of the projects that were in use targeted .NET 4.5. The overall web.config of the project contained the following line:

<compilation debug="true" targetFramework="4.0">

The fix was to change it to:

<compilation debug="true" targetFramework="4.5">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM