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

后端 未结 9 2189
梦毁少年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:38

    I installed Microsoft.CodeDom.Providers.DotNetCompilerPlatform for my web project and then removed the package. The error went away.

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

    JUST RIGHT CLICK ON YOUR SOLUTION PROJECT AND CLICK ON CLEAN. I HAVE DONE THAT AND IT DID WORK FOR ME. I AM SHARING THIS BECAUSE WHO KNOWS IF IT HELPS SOMEONE ELSE LIKE IT HELPS ME.

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

    After trying a variety of the solutions proposed here, it turns out that simply quitting Visual Studio 2015 and then restarting it was enough to get the Solution/Project to successfully compile once again.

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

    Two things i did to resolve this was to re-target the framework and then changing it back (was using 4.5.1 changed it to 4.5 and back)

    After this i had a lot of error with T4MVC which i was also using, i upgraded it to newest version but i could see that in source control that T4MVC was installed targeting framework 4.5 and when you re/install a new nuget package it changes the target framework, so that was changed to 4.5.1

    After this everything worked. I didn't test if you only need to do that second part of this answer, but i would try that first.

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

    I've found that if I have the files in App_Code open in Visual Studio 2015 when I run the build, then I don't get the errors. As soon as I close the files the errors show up again.

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

    I had the same issue.

    I manually edited the generated file file.cshtml.72cecc2a.cs (it was at AppData\Local\Temp\Temporary ASP.NET Files\root) and changed ASP.global_asax to System.Web.HttpApplication and the error went away.

    This is the generated code:

    protected static ASP.global_asax ApplicationInstance {
        get {
            return ((ASP.global_asax)(Context.ApplicationInstance));
        }
    }
    

    I changed it to:

    protected static System.Web.HttpApplication ApplicationInstance {
        get {
            return ((System.Web.HttpApplication)(Context.ApplicationInstance));
        }
    }
    

    I don't know why this is happening though.

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