36

I am experiencing an error that I am unable to resolve for some time now. I was wondering if someone can help identify the cause of this error? I am completely new to asp / asax. After some research, I think that the error I am getting is due to the web application trying to use outdated code. I was thinking to rebuild the c# file using Visual Studio and/or the entire project. However, I am completely new to C# and asp, and was wondering can give me some suggestions if this may fix the problem and/or if there is an possible alternate solution.

Error message

Parser Error Message: Could not load type 'Inventory1.Global'.

Source Error:   <%@ Application Codebehind="Global.asax.cs" Inherits="Inventory1.Global" %>

Entire Global.asax contents:

<%@ Application Codebehind="Global.asax.cs" Inherits="Inventory1.Global" %>
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
  • Don't expect us to magically solve your problems by providing only two lines of code that does't mean anything to us more than they do to you!.. Please explain your problem in more detail.. Why are you inheriting Inventory1.Global class for the global.asax ? Do you know anything about global.asax and how it is formed? is there anything else in that file? what are the contents of the Global object? – Subliminal Hash Feb 25 '13 at 16:16
  • 1
    As you figured it out, you seem to be missing the Inventory.Global which should be located in Inventory1.dll in the /bin folder of your webapp. (Re)Building the whole webapp seems like a good idea – jbl Feb 25 '13 at 16:16

23 Answers23

52

Try replacing CodeBehind with CodeFile

Taha Rehman Siddiqui
  • 2,441
  • 5
  • 32
  • 58
  • 8
    Could you please explain why this solved AnchovyLegend's problem? I'm getting the same issue but I would like to know why this would fix the issue before I apply it. – John Odom Jun 22 '16 at 22:07
  • 1
    I dont remember exactly what led me to do this but it had something to do website and webapplication type of aspx projects. – Taha Rehman Siddiqui Jun 27 '16 at 03:13
  • Wonderful solution! – Keval Gangani Sep 07 '16 at 11:23
  • 5
    This advice would appear to change the nature of the project. See http://stackoverflow.com/questions/73022/codefile-vs-codebehind - this changes it to compile-on-the-fly. – TrueWill Apr 10 '17 at 14:50
  • In my case, auto document generator has added description in global.ascx. – Kiya Feb 13 '20 at 09:35
  • This did not directly fix my problem, but other compile errors started to appear when I did it. I fixed those errors, switched back to `CodeBehind`, and I'm running! – Homer May 26 '22 at 19:56
9

Could not load type

means that a type could not be loaded. (In this case, "type" refers to Inventory1.Global). Types are located in compiled DLLs. So, either the DLL isn't available, is out of date, or doesn't contain a public type with the given name.

Some possible causes are:

  • You have no type declared with the given name. For your example, you should have the following:
namespace Inventory1 {
  public class Global {
  ...
  }
}

Note: avoid names like Inventory1. They imply that there is an Inventory2, Inventory3, etc., which is bad practice as they're abmiguous and not very descriptive. Also, Global is pretty vague, and may introduce confusion with the global namespace.

  • Make sure your cases match (Inventory1, not INVENTORY1.)
  • You haven't compiled the project. In VS, rebuild the solution.
  • The assembly that declares the class has a compilation error, so the relevant DLL is either missing or out of date. Make sure you've resolved all errors.
  • The class is not marked as public.

If I had to guess, I'd put my money on a compilation error. Unlike PHP and other interpreted languages, C# have to be successfully compiled before they can be used.

3Dave
  • 28,657
  • 18
  • 88
  • 151
  • 1
    Thanks for the reply. When I try to rebuild solution Inventory1 using VB, I get many errors and warnings, here is a screen shot: http://oi48.tinypic.com/288bea9.jpg – AnchovyLegend Feb 25 '13 at 17:06
  • 2
    That's why you're getting the runtime error. You'll have to resolve those before you can run the page. – 3Dave Feb 25 '13 at 17:10
  • Yes I know, however, I doubt there that many errors exist as the application was work fine about a month ago. I think the problem is more simple, than troubleshooting one error at a time, any ideas? – AnchovyLegend Feb 25 '13 at 17:12
  • @MiGusta Start with the first two errors. Missing `End Class` and `End Namespace` will cause a lot of other errors. Resolve those two, rebuild and see where it gets you. – 3Dave Feb 25 '13 at 17:12
  • @MiGusta Update your question with the source for that file. – 3Dave Feb 25 '13 at 17:12
  • Also, the errors in your screenshot are VB errors, but your source file references `global.asax.cs`. Are you working in C#, or VB? – 3Dave Feb 25 '13 at 17:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25087/discussion-between-david-lively-and-mi-gusta) – 3Dave Feb 25 '13 at 17:15
  • @MiGusta what was the problem? – 3Dave Mar 04 '13 at 17:04
7

I had this error , just needed to rebuild the project

5

I faced this issue and i got the solution from here and i would like to share it.

SOLUTION Empty the bin folder. Build all the dependent class libraries and refer them in the main project and build the complete solution.

I did this and it worked like a charm for me !!

Community
  • 1
  • 1
Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
3

After scouring around for what could have caused this I found a few things that I needed to do to get my project running...

(Note: You may not need to do all of these - it is a case-by-case thing)

  • If you did any changes from IIS Express to Local IIS you may need to change the build configuration from bin/debug to bin. (Right click on solution >> Properties >> Build >> Output)

  • If you have a URL rewrite then you will need to install URL rewrite on your Local IIS.

  • Navigate to your applicationhosts.config file (usually it's some place like C:\Users\username\Documents\IISExpress\config) and rename the file to applicationhostsOLD.config.

  • Clean and rebuild your project. You may need to go manually empty out the bin.

Now you should be good to go.

maxshuty
  • 9,708
  • 13
  • 64
  • 77
3

Since it was only happening with IISexpress, changing output from bin\Debug\ to bin\ solved it for me. Changing tag CodeBehind to CodeFile only created even more problems.

Micael
  • 31
  • 5
  • The reason is not the IISExpress though. It's because the Macro in Visual Studio set the targetDir as *\bin\ not *\bin\Debug. You can also just change the TargetDir and related Macros to bin\Debug and it should work. Although the later is more complicated. – Weihui Guo Dec 13 '18 at 19:15
1

This happened with me on my local machine. The issue was incorrect IISExpres config. If you are getting this issue on your local environment (Visual Studio debug runs), check the IIS Express config file. Make sure your local site/application path is pointing to the correct location.

The configuration file is called applicationhost.config. It's stored here: My Documents > IIS Express > config . Usually (not always) one of these paths will work:

  • %userprofile%\documents\iisexpress\config\applicationhost.config
  • %userprofile%\my documents\iisexpress\config\applicationhost.config
Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
zwooter
  • 11
  • 1
1

It can't find the necessary file in dll assembly. Rebuild the project, Rebuild the solution and then try it again.

Md Shahriar
  • 2,072
  • 22
  • 11
1

I added a new build profile and that defaulted to output of /bin/[new profile name] and when i was running debugger it was trying to look to just /bin

workabyte
  • 3,496
  • 2
  • 27
  • 35
0

It's likely that you renamed something. Check the Global.asax.cs file for the class declaration and make sure that the namespace and class name match exactly what's in the asax file. This includes case! Can you copy/paste the namespace and class declaration of the .cs file into a post here so that we can compare?

DiskJunky
  • 4,750
  • 3
  • 37
  • 66
  • Thanks for the reply. Class declaration: `public Global() { InitializeComponent(); }` and namespace `<%@ Application Codebehind="Global.asax.cs" Inherits="Inventory1.Global" %>` – AnchovyLegend Feb 25 '13 at 16:35
  • is there a `namespace` declaration in the .cs file? – DiskJunky Feb 25 '13 at 16:39
  • ok, now check that the project name (go into Project Properties) matches and that the Default Namespace matches as well. Everthing has to tie up or you get an error like what you're seeing. If none of that works then it might be easier to just restart the project from scratch – DiskJunky Feb 25 '13 at 16:50
  • here is a screenshot of the errors I am getting when trying to rebuild solution in VB: here is a screen shot: oi48.tinypic.com/288bea9.jpg – AnchovyLegend Feb 25 '13 at 17:10
  • in VB? The Gobal.asax is a C# file... have you started a new project or is this the same one? – DiskJunky Feb 25 '13 at 17:33
0

Parser Error Message: Could not load type __

After doing everything suggested in the comments above, with no luck, refreshing (uploading) the contents of /bin to the server worked. The files uploaded to bin are the: dll, pdb and xml. Don't know which one did it.

The problem I had here was induced by renaming a file (_.aspx) in Solution Explorer.

Neil
  • 21
  • 5
0

Rebuilding/re-publishing my project/solution to the server did nothing to help me, and I doubt that will help that many out of this predicament. For me, I did a few things to troubleshoot this that eventually got me out of this "hole".

I had been trying to use a binding on the web site, but this wasn't working. I tried calling the site with http://localhost/Report.aspx (this was my homepage, which I opted to not call Default.aspx - I was going to update the "Default Documents" section with the name later) when I got the Parser Error the OP saw. So I tried some things:

I stopped the old project's website and built another, simple web project, that had "hello" and a label on the page and nothing else. I had a line in the Page_Load to populate the label's Text property with "world!", just to make sure that part was working. I created a new website on port 80 and transferred the published contents of my site to the server. So even though I had .NET 4.5 installed on the server (and had ran the aspnet_regiis -i command from the 4.0 directory) and the App Pool in IIS that I was using for this new project was set to 4.0, the browser complained about the web.config having a targetFramework=4.5.2 in it, which is Visual Studio 2015's default framework. So I installed .NET 4.6 (NDP46-KB3045557-x86-x64-AllOS-ENU.exe), restarted the server, and then my simple site worked. So then I deleted this site - all I wanted to do was prove my installation steps were accurate and the server could run a site.

So then I went back to my original project/site - I deleted and re-created the web site. I put the Application Pool to the one I had originally created for this, which I ensured was running .NET 4.0. Once I did this, I navigated to my site and everything worked when using http://localhost/Report.aspx. So it seems to me what causes this is what version of the .NET Framework you are using.

vapcguy
  • 7,097
  • 1
  • 56
  • 52
0

I tried all the solutions listed above and none of them worked. I finally created a new web page (webform) and copy blocked all the code (cs and aspx files) into it from the old one, deleted the old cs and aspx file, recompiled, and now I'm back in business. I know it makes no sense. It should not have mattered, but it worked.

SteveFerg
  • 3,466
  • 7
  • 19
  • 31
0

Please try to open your project as Project/Solution, most probably it will resolve the error. This type of error Could not load type.... occurs when we try to open project as website.

I have tried to open my project as solution and it resolved my problem.

0

Please check namespace and class name at all places, In one case, One team member changed namespace and I was using old namespace in .aspx file. It was causing issue. I updated namespace and it got working.

Sanjay Sharma
  • 635
  • 8
  • 10
0

I was fixing my namespaces in our Base Project, and I started seeing this error on another project that references it after that. I had to remove the reference to the Base Project and re-add it and then it started working again.

OJisBad
  • 367
  • 4
  • 9
0

I just got this error today. It turns out that it was because I reverted by mistake the project file to an older version that didn't include the page anymore.

boggy
  • 3,674
  • 3
  • 33
  • 56
0

I had the same issue after renaming an aspx page Visual studio renamed it but dropped the namespace. Make sure the Inherits property contains the fully Qualified name including the namespace.

Mark Redman
  • 24,079
  • 20
  • 92
  • 147
0

If you just added the new aspx File, rebuild the project it is located in. The problem comes from your Code Behind file that isn't compiled at the moment, therefore you want to access a newer page that doesn't exist in your current compiled project dll

Jamates
  • 1
  • 1
0

I had this problem on the remote server, but not on my local server. After trying everything and nothing working, I finally resolved it. My domain name was pointing to a directory under another domain. I had originally built the website independently in Visual Studio as its own project. No matter what I did, it wasn't working anymore. So I moved it to a folder inside of the project for the main domain name and uploaded it as part of the main project.

For example, I have say domain name AAA.com with a website of its own. And then I also have BBB.com that points to a directory under AAA.com's main directory. Originally I had separate VS projects for AAA.com and BBB.com, but that wasn't working anymore. So I had to move all of BBB.com's files to the AAA.com project and set it up exactly like it appears on the remote server. For some reason, that worked.

0

Try This It will Definitely work :- Parse Error:

May be you Class name is not matched with the webform name

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 08 '21 at 16:38
  • This is covered extensively by [@3Dave’s answer from eight years ago](https://stackoverflow.com/a/15072268/3025856), and with far more clarity. Please review that post as a good example of how to answer. – Jeremy Caney Dec 08 '21 at 18:00
0

Had this within IIS whilst deploying, It turns out I didnt correctly turn the folder into an application which caused this error

0

I my case the assembly of the ASPX projet/application was in the GAC, from a previous version, and my new Test.aspx has was giving this error: "could not load type"

I've put and underscore ("_") in front of the name of the DLL in the GAC, so it will not be found, then it works.

Looks like ASP.NET was loading the assembly from the GAC and ignoring the assembly in the IIS path, /bin of the application.

gharel
  • 413
  • 4
  • 13