In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code:
<%@ Application CodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %>
However when I build I get an error stating-
Could not load type 'MyNamespace.Global'.
This seems to be because the MyNamespace namespace (defined in the code behind file Global.asax.cs) is not seen by the compiler in the Global.asax file (does not show in R# intellisence..). This turned out to be a very hard nut to crack... any help will be appreciated!
Note: The Global.asax and the Global.asax.cs are located in the same folder.
Note2: When compiling from the vs prompt with csc it compiles o.k.
Well In my case VS 2017, the lightweight solution load was causing this issue. I disabled it & restarted VS then re-build my solution & the problem gone.
I experienced a similar error when having a
tag as a child (the first child) of the
tag in my Web.config. I had inserted the tags in my web.config in an attempt to prevent configuration inheritance in an application deployed under the 'Default Web Site' in IIS.
I've run across this issue a few times and in each case I was rebuilding a computer or switching to a new computer. My first step (besides updating the machine and installing Visual Studio) is to pull my projects down from Git and test them.
I hit this error each time because I tried to access my local code before compiling it. You see, I have Git and Subversion setup to ignore my bin/build folders, so after a pull from my repository I forgot to run a build which pulls required packages from Nuget (since I have Git/SVN ignore those too) and creates the DLLs needed to actually run my app.
I doubt this will resolve most people's issues, but I didn't see it on the list of potential solutions so I thought I'd add it.
None of these worked for me, unfortunately. The fix I found was more specific to development, specifically, debugging on your local machine. Also unfortunately, it doesn't really fix the issue in the way I was hoping, but if you're at your wit's end, this might get you running again.
TL;DR: In the project properties, in the web tab, under Servers, Select Use Local IIS Web Server. The address,
was already populated (I have IIS7, .NET 4.0). What was originally selected was the "Use Visual Studio Development Server" with a Virtual path of "/"
What's really puzzling to me is the fact that nothing else worked, I went through all of the suggestions I could find on SO, and nothing would work. The weird thing is, the error was (seemingly, it's been a few months since I last looked) manifested when I added a new ascx file that was similar to an existing one that was added from an old .net 2.0 (I think) project that would allow for custom user management from within the application. It was working, beautifully, for a long time, until I tried adding this new file. After adding it, and seeing the error, I promptly reverted all changes, but the Global.ascx error would not go away, not even blowing away the whole project and re-getting latest from source control.
I had to delete (duplicate) files from disk that were not included in the project. Looks like the duplicates were caused by a failed rename. The file names were different, but same code.
After deleting all the oof.* files I was able to scan.
I've tried to rebuild solution and clear ASP.NET Temporary files without success.
But after run IISRESET the error disappeared.
Update: I had the same problem again 1 month later. I've noticed that MyWebsite.DLL exists in bin folder, but doesn't exist in Temporary ASP.NET Files (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files). I've tried a few things, that are suggested on this and "Parser Error Message: Could not load type" in Global.asax questions (I actually forgot about my own answer), but the error disappeared again only after IISRESET