Parser Error : Could not load type after changing output dir in asp.net web app
Solution 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
Solution 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.
Solution 3
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.
Solution 4
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.
Jim Andrakakis
I'm a scrum master and senior software engineer, mainly working with C#, Powershell, Oracle and MS SQL Server. I've worked in a wide variety of software sectors such as education, GIS, engineering, ERPs and warehouse systems, banking, insurance and medical devices.
Updated on June 05, 2022Comments
-
Jim Andrakakis almost 2 years
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 emptyASP.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 thedebugger
. 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 ?????