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 :
- Clean the project output i.e. delete everything from the bin folder
- 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 ?????
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