Parser Error Message: Could not load type 'sometype'

76,483

Solution 1

Try replacing CodeBehind with CodeFile

Solution 2

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.

Solution 3

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 !!

Solution 4

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.

Solution 5

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.

Share:
76,483
AnchovyLegend
Author by

AnchovyLegend

Updated on December 09, 2021

Comments

  • AnchovyLegend
    AnchovyLegend over 2 years

    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" %>