Reputation: 2375
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.
Upvotes: 111
Views: 145763
Reputation: 101
We have a .net app running on a PROD server. When we copied the bin folder to the server for the latest release, we got the same error. We couldn't understand what was going on. It worked fine locally and on the TEST server. After some digging I noticed that some of the uploaded files had a size of 0 bytes.
It turned out it was the FTP client (Filezilla) that corrupted some of the uploaded files, which understandably made .net think some libraries was located elsewhere or missing.
We tried another FTP client and re-uploaded all files. And that seemed to have done the trick.
Upvotes: 0
Reputation: 793
Having been in the development game for almost 20 years, this chestnut has continued to plague me across multiple projects.
As such, today whilst experiencing this same problem again, against another project, I decided to investigate further and I do believe this is related to Bin folder location... or more specifically, the output path of the bin folder.
For me, for a simple service based web application configured to run/debug through IIS, it was changing the output path from bin\debug to bin\ that resolved it
Project > Properties > Build > Output path
Seriously hopes this helps.
Upvotes: 1
Reputation: 6672
As silly as it may sound. Here is what I did..
My project was targeting 4.6.1 version. Changed the target version to 4.6.2. built it. deleted obj & bin folders. & once again changed the version to 4.6.1. Bingo!!
Upvotes: 0
Reputation: 1561
I experienced this problem when I accidentally set "Chrome" to be the default browser for debugging. When I set it back to "IE" the problem disappeared. I am not sure why...
EDIT: I was about to delete this answer, because I wasn't sure about it, but then I had the problem again. I switched to browsing with Chrome, then back again to IE and it stopped! What gives!?
Upvotes: 0
Reputation: 823
Just wanted to add my two cents. I was receiving the same error, and I tried all the suggestions to no avail. My situation is probably different?
Turns out, an auto-generated "AssemblyInfo.cs" file had some extraneous spaces, which was preventing me from launching the web app (via debug). Here's what the file looked like:
[assembly: AssemblyTitle("WebApplication2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("
")]
[assembly: AssemblyProduct("WebApplication2")]
[assembly: AssemblyCopyright("Copyright ©
2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
After killing the spaces in the AssemblyCompany and AssemblyCopyright, I was finally able to build and launch the project.
Observed in the following environment: --Visual Studio 2017 Community version 15.3.0 --Win 7 x64 Enterprise --New Project > Visual C# > Web > ASP.NET Web Application > Web Forms
Upvotes: 0
Reputation: 31
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.
Upvotes: 0
Reputation: 28463
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
Upvotes: 0
Reputation: 759
If you are using Visual Studio, You probably are trying to execute the application in the Release Mode, try changing it to the Debug Mode.
Upvotes: 0
Reputation: 863
I had this issue when deploying on prod server only. In my other environments it works... I just deleted stuff in the bin folder then republish and it work after that.
Upvotes: 0
Reputation: 51
Works Fine For Me IN VS 2015.Now I can Use Global event. My Global.asax
file has this Line
<%@ Application Language="C#" CodeBehind="~/App_Code/Global.asax.cs" Inherits="Global" %>
And I make class file Global.asax.cs
that is in AppCode
folder that look like
public partial class Global : HttpApplication
{
public Global()
{
//
// TODO: Add constructor logic here
//
}
}
I hope this will help
Upvotes: 5
Reputation: 1239
In my case, I had added Global.asax to a WCF project to experiment with it, but decided to remove it. I removed it from Solution Explorer, but because it was still in the folder, the pipeline was still finding it and causing this error.
I removed the Global.ASAX and GLobal.asax.cs from the filesystem and that did resolve the error.
Upvotes: 1
Reputation: 2015
in my case it was IISExpress pointing to the same port as IIS to solve it go to
C:\Users\Your-User-Name\Documents\IISExpress\config\applicationhost.config
and search for the port, you will find <site>...</site>
tag that you need to remove or comment it
Upvotes: 0
Reputation: 1830
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.
Upvotes: 0
Reputation: 726
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.
Upvotes: 1
Reputation: 20230
When I encountered this problem most recently I tried everything mentioned here but to no avail. After tearing my hair out I decided to try deleting my entire code base (yes, pretty desperate!) and then re-downloaded everything from my code repository. After doing this everything worked fine once more.
Seems an extreme solution but just thought I'd include it here as it hasn't been mentioned before in this thread.
(Note that the other time I have encountered this issue, is when the Global.asax was inheriting from a component which needed to be registered on the host machine. This was missing hence I got this same issue).
TL;DR; If all answers in this thread don't work for you, try deleting and then re-downloading your entire code base!
Upvotes: 1
Reputation: 945
In my case, It was because of my target processor (x64) I changed it to x86 cleaned the project, restarted VS(2012) and rebuilt the project; then it was gone.
Upvotes: 1
Reputation: 169
I am new to asp .net developement and I faced the similar problem.
I updated the class as a partial
class and it worked fine.
public partial class Global : System.Web.HttpApplication
Upvotes: 16
Reputation: 28730
I had converted my solution from VS2003 to VS2010 and had had problems converting the web application project.
I experienced the exact same problem and none of the answers worked for me.
What worked for me was:
it would seem that the problems I had during the conversion had removed the web application project from the build for some reason.
Hopefully this answer helps anyone else that has the same problem...
Upvotes: 2
Reputation: 3300
One situation I've encountered which caused this problem is when you specify the platform for a build through "Build Configuration".
If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET expects the assemblies to be output to the Bin folder.
What I found in my situation was that they were being output to both (Bin and Bin/x86/Debug), with the exception that some of the dll's, and inexplicably the most important one being your web application dll, being missing from the Bin folder.
This obviously caused a compilation problem and hence the "Could not load type Global" exception. Cleaning the solution and deleting the assemblies made no difference to subsequent builds. My solution was to just change the output path in project settings for the web app to Bin (rather than bin/x86/Debug).
Upvotes: 167
Reputation: 61037
Here's another one for the books. It appears that this happens when you launch more than one web application from the same port number.
Basically, I have a couple of branches that I work off, I have a main branch and a staging branch and a release branch. When I switched branch to the staging branch I noticed that it was using the same port address configuration so I opted to change that. I then received another warning that this reservation conflicts with another configured application. The IIS Express server is sensitive about that and for whatever reason it bricks the configuration.
By simply picking a third unaffected port this problem went away because it then maps the port to a new directory mapping (my branches are located differently on disk). I noticed this because I tried to change the type name pointed to by Global.asax
but the type name was unchanged even after restarting the server, so clearly, the code I was changing wasn't reflected by the IIS Express deployment.
So, before you lose too much sleep over this, try changing the IIS port number that is currently used to run the web project.
Upvotes: 5
Reputation: 11
This work for me: First thing: it's seem that no matter what did you say to visual studio, the ide always look the file in: bin (for web app and off course in my case) So, even when i said to visual studio a specific path to load file, the ide keep looking for the wrong path. So i change in the: Build/Configuration Manager the output type to: Release (previous i clean up the solution, even manually) so, when the file .dll was created then i moved manually to "bin" folder under the project/solution folder. Hope this will be helpfull !!
Upvotes: 1
Reputation: 5780
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,
http://localhost/MyApp"
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.
Upvotes: 2
Reputation: 2169
I had a similar issues where I was receiving this error on a project.
“Could not load type [Namespace].Global
Error in Line 1 etc etc
After spending some time I suspect a function with possible errors in a Class ..later commenting that specific function my problem get resolved.
I dont know why Visual Studio did't give me that specific error at debugging time. But this error might occure due to some errors in class file..
Upvotes: 1
Reputation: 933
Change the GUID of the assembly. This fixes many MANY problems, I have found.
Upvotes: 1
Reputation: 1
go to configuration Manager under properties for your solution. Then make sure all projects and getting built, and this won't be a problem.
Upvotes: 0
Reputation: 319
I experienced a similar error when having a
<clear/>
tag as a child (the first child) of the
<assemblies>
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.
Upvotes: 3
Reputation: 3313
Old post but I go this error when trying to convert from website project to web application project.
Follow the instructions on this Link. I still got the global.asax error but all I did was delete it and re-add it back by right clicking on the project in visual studio and selecting add new item. Add the global.asax file and it worked.
Upvotes: 2
Reputation: 3611
I was befuddled by the same darn issue. I tried to remove and and the global.asax
(closed VS2010 before adding). Cleaned the project/solution, checked for any changes in the web application configuration and other stuffs that had worked for other people here in SO threads. I finally cleaned the solution, deleted the bin/obj folders and stopped any running VS2010 development servers then I reverted all the changes back and found the application was running again. I redid the same things and now its working fine.
Happened again and this time this solution worked for me.
Upvotes: 0