Today I got this error message: "The type ‘<class>’ exists in both ‘<dll location>’ and ‘<dll location 2>’"

I remembered I encountered it before, but I didn’t remember the cause, nor the remedy.  That’s why I keep this blog to post such things that you learn somewhere that, by the time you get the same problem again, you’ve forgotten the solution and you can get back here and help yourself.

I remember I had this error message before, so I went to my own blog searching for the solution, but it wasn’t there.  I either forgot to blog about it then, or it must have been before I started to use this blog as my extended memory.  So now it’s time to store this solution in the extended memory right away.

The reason why you get this problem is that there are 2 dynamically created dll-files defining the same class.  At compile time, there’s no problem, so it must be a problem in the aspx-pages themselves.

I didn’t have time to figure out what the real cause was, but Google came up with 2 forum post which gave me the answer (of course there were more, but why look further?):

ASP.Net Forums and MSDN Forums

The problem with me was that I had a CodeFile="Page.aspx.cs" in the Page directive in the Page.aspx file.  It’s automatically generated when you create a new page, and it didn’t cause me any trouble before.  The only thing I was doing today, was refactoring my base page and master page.  So there must have been some confusion there.

I don’t know wether this is a bug, or my stupid mistake, but anyway, after replacing "CodeFile" with "CodeBehind", everything went back to normal and the pages worked again.

So the next time I receive this error, I know how to resolve it.