“ASP.global_asax does not exist in the namespace ASP”

后端 未结 9 2190
梦毁少年i
梦毁少年i 2020-12-23 08:56

I created a RazorFunctions.cshtml file on App_Code

@functions {
    public static string GetActiveClassIf(string controllerName, string actionName = null)
           


        
相关标签:
9条回答
  • 2020-12-23 09:52

    Code placed in App_Code folder is treated a bit different, it is compiled at runtime. cshtml file is 'Content' so that could be the reason why you get errors. Create normal folder within your project name it Code or something similar (but not App_Code) and place your file there.

    0 讨论(0)
  • 2020-12-23 09:54

    After further investigation I found that this is a known issue.

    source: https://support.microsoft.com/en-us/kb/3025133

    ASP.NET and Web Development

    • When you create a Web Forms 4.5 WAP and open a Web Form page, you receive the following errors in the Errors List window:

    • The project will run without any issues. Error CS0234 The type or namespace name 'global_asax' does not exist in the namespace 'ASP' (are you missing an assembly reference?) Error CS0234 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) Assume that you use new language features for C# and VB in Visual Studio 2015 RC. You receive a runtime error when you use C# or VB in a Web Form page or in Razor Views.

    To work around this issue, install Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package. This package will substitute the Roslyn-based provider for the in-box CodeDom providers for ASP.NET.

    0 讨论(0)
  • 2020-12-23 09:54

    The way I resolved this error was to move my code form Global.asax.cs into Startup.cs and delete Global.asax so that there aren't any codebehind files in my project. See this question for more info.

    0 讨论(0)
提交回复
热议问题