Skip navigation.

Addition Of External Online ToolsAll recent postsCode Mangling Explained

Remember To Recompile

This seams like a trivial issue but it might take several hours of hair pulling to figure it out. You mostly don't see this happen in Visual Stuio.NET. Problems creep in once you upload changes to a live site. Here's what I'm talking about:

Parser Error Message: Could not load type 'DebugTest.test'.

Suppose you added a new page to your web app. You've been running it fine, you've been debugging it fine. Then you copy the page to a live site and... get the error above. What's happening?

You forgot to also deploy a compiled assembly. I mean the assembly where the code behind for this page resides. Your page has a line similar to this one:

<%@ Page language="c#" Codebehind="test.aspx.cs" 
AutoEventWireup="false" Inherits="DebugTest.test" %>

Pay attention to the Inherits attribute. The ASPX page expects to find the class test in the DebugTest assembly. Since you didn't re-deploy the binaries your compiled assembly simply misses this class which is why you get the said parser error.

Sometimes you don't even need code-behind. You have no server-side logic involved, but only HTML with or without JavaScript. Do yourself a favor and remove the Codebehind and Inherits attributes. There's no need to drag around a compiled class that does nothing. A stripped-down page declaration will look as follows:

<%@ Page language="c#" AutoEventWireup="false" %>

I also noticed, thanks to Lutz Roeder's Reflector, that if you remove both Codebehind and Inherits but keep the code-behind .cs file in the project tree Visual Studio.NET still compiles it even though no code-behind logic needs to be invoked. I removed both the .cs and .resx files which produced a leaner assembly.

A friend of mine spent half of his Saturday before he called for help. All he really needed was this quick fix. I just wanted to post this as a reminder.

Comments

Comment permalink 1 Mohd Hassan |
Hi,
This is relevant to the article "Remember To Recompile", I think. Say, I have a live asp.net on a server. Right now whenever I have changes to the code behind of a page, no matter how small the changes are, I will replace the whole application on the live server with the one with changes - which is ridiculous. I know there is a better and more efficient way to apply the changes without replacing the whole application.
Would somebody please let me know how to do this.
Thank you
Comment permalink 2 Milan Negovan |
It depends. If your assemblies are strongly-typed you either have to recompile and redeploy them all, or specify a policy to have a newer DLL(s) loaded.

If you make a change only in an ASPX file, it's just HTML so you can simply upload just this one file.

If you make a change in a code-behind file, you need to recompile so the change makes it into the DLL and redeploy this one DLL. If your DLL is strongly signed... see above.
Comment permalink 3 Len |
I would like to update a class in a .NET dll. The dll contains other classes as well. However, I only have the source for the class I want to update. Is there a way to update only that class in the dll?
Comment permalink 4 Milan Negovan |
You'd need all source files (along with the modified one) to recompile your DLL.
Comment permalink 5 Conor |
I'm REALLY new to all of this... so i have a question thats probably going to sounds REALLY stupid....
But HOW do i recompile a page?? I have NO experience with ASP beyond simple changed to the aesthetics of the page, all done in HTML really, which all worked fine when i uploaded the new files. Now i'm tryin to change prices and stuff on the site... which are objects that carry over to a 'confirmed order' page if you will...
I'm told i need to recompile the entire site... How do i do this?
does the .csproj file have anything to do with it?
Is the .dll file where it's all compiled to?
If so, if i delete the .dll, on my next attempt to access the site, will it be all messed up, or merely created a newer dll file?

REALLY need some help on this...
Thanx.

Conor.
Comment permalink 6 Milan Negovan |
In a nutshell: yes, you need to load the project file, .csproj, in Visual Studio.NET and recompile it. All of your C#/VB.NET code is compiled into assemblies (DLLs). They go into the bin folder.

What you deploy is your aspx along with html pages. Put compiled assemblies into the bin folder.

If you delete a DLL your site will get messed up. Replacing Dlls is easy---just copy a new one on top of an older one.
Comment permalink 7 Conor |
Cheers Milan

Had no idea what program to use. Appreciate the input :-)

Conor.
Comment permalink 8 lan |
Conor,

Use VS.NET to do it.
Comment permalink 9 Charles |
I have third party tool that promised a lot of the ability to customize. However, when I look the code behind section, the file is a dll(Codebehind="something.dll"). I would like to be able to view the source code. NEED help badly.
Comment permalink 10 Milan Negovan |
Looks like you'll have to decompile it. My favorite tool for this is Reflector.
Comment permalink 11 Sonali |
I had developed a project in asp.net which contain admin subdirectory
into it. site work fine when code is executed outside the admin directory. but if I try to access pages inside admin directory it gives
me error. Could not load type .
I know that it is because directory level problem but how to solve it.
Comment permalink 12 Milan Negovan |
There can be a number of reasons for this to happen. For example, you might have two default.aspx pages: one in root and one in admin. It's hard to tell without knowing more about your project.
Comment permalink 13 Andy |
I have a live web app which was developed by others. It contains a Crystal report (customers.rpt). Now I want to modify this report without changing its displaying data, just make it look nicer. Do I have to recompile the whole app?
Highly appreciated

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):