3

This isn't really a question on a problem; I've solved it my own (after banging my head against a wall for a couple of days) and I'd like to share it, but I'd be REALLY interested if someone can give me an explanation on why this happens.

The situation is simple enough : In C# 4.0, VS 2010 (haven't tested in other configs) create an empty ASP.NET web application

: File -> New -> Project (not Web Site) -> Web -> ASP.NET Empty Web Application.

In the newly created web app, create a page (add -> new item -> web form). Then run the project and, ofcourse, it works.

Now do the following :

  1. Clean the project output i.e. delete everything from the bin folder
  2. Change the project's output folder : project properties -> build -> output path. E.g. change bin\ to bin\debug (that's what I did)

BANG ! The project no longer works ! Try starting it (F5) and you get :


Server Error in '/' Application.
Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'WebApplication2.WebForm1'.

Source Error: 


Line 1:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
Line 2:  
Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Source File: /WebForm1.aspx    Line: 1 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237 

If you don't do step #1 (delete everything from the bin folder) the project works but when you change the code inside WebForm1.aspx.cs you start getting "Source file not found" messages from the debugger. As I understand, for some %$&^#$^* reason, it still uses dlls from the bin folder.

It looks like the output folder is hard-coded somewhere... ?! Does anyone have any idea on why on earth does this happen ?????

5 Answers 5

2

I know it's too late, but if somebody else is looking for this. I had the same issue and what I found that bin folder was not included in the project. Include bin folder in the project, build it and it should be fine.

Sign up to request clarification or add additional context in comments.

Comments

1

The project no longer works

Hmm well that's not quite right. The project is fine. VS is dutifully creating the dlls where you want them to. Its just not where you should be creating the folder.

What you're really asking is why won't ASP.NET load a dll from a random sub folder of bin. There are only a few locations that ASP.NET will look for assemblies. Aside from the bin there also the GAC and the .net Framework folder (but I suspect that's only for .net Assemblies). I don't know why but I suspect its to remove the need for you to tell it where to find it (Ala registry settings)

You could create your own Assembly loader but you'd need a way to communicate to your loader where the files are. You'd also probably need to put that assembly loader assembly in the bin.

Save yourself some grief and put the dlls in the bin folder so that ASP.NET will load them

As a side you note you may ask yourself what's this output directory for. The typical use case is libraries that are referenced by other assemblies. Also executable files can be put anywhere since they are the entry point rather than ASP.NET

1 Comment

I guess you're more or less right; what I'm actually asking is why the ASP.NET debugging server doesn't load the dlls from the output directory, whatever it is.
1

What I did was just delete all of the .dll files from your project(\bin;\debug;\Release) added a new item (which page to test) to the project and tried it in new page.

It works. Then, set the start page to the problem page which caused the error and try again, it works this time.

Comments

1

As a warning: This can also happen if your Web.config's configuration/system.web/compilation/assemblies gets messed up, especially if you add a <clear /> and IIS can't find some important assemblies.

Comments

0

Although not directly related to your scenario, this error can also come due to the ASP.NET runtime being unable to locate the /bin folder.

For this, make sure you have marked the virtual directory containing your application as a web application root.

e.g. In godaddy web hosting you should mark Set Application Root to the folder/sub-folder containing your application. Making it a virtual directory is not enough.

Hope it will help someone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.