Where Does Error Cs0433 "Type 'X' Already Exists in Both A.Dll and B.Dll " Come From

Where does error CS0433 Type 'X' already exists in both A.dll and B.dll come from?

Theory

When this issue is not caused by a bug in the application (e.g., duplicate class name):

This issue appears to present after a change is made to the application's project that results in a new build (e.g., code/reference/resource change). The issue appears to lie within the output of this new build: for various reasons Visual Studio is not replacing the entire contents of your application's obj/bin folders. This results in at least some of the contents of your application's bin folder being out of date.

When said issue occurs, clearing out the "Temporary ASP.NET Files" folder, alone, does not solve the problem. It cannot solve the problem, because the stale contents of your application's bin folder are copied back into the "Temporary ASP.NET Files" folder the next time your application is accessed, causing the issue to persist. The key is to remove all existing files and force Visual Studio to rebuild every object, so the next time your application is accessed the new bin files will be copied into the "Temporary ASP.NET Files" folder.

Solution

  1. Close Visual Studio
  2. Perform an iisreset
  3. Delete all the folders and files within the "Temporary ASP.NET Files" folder (the path is referenced in the error message)
  4. Delete the offending application's "obj" and "bin" folders
  5. Restart Visual Studio and open the solution
  6. Perform a "Clean Solution" followed by a "Rebuild Solution"

Explanation

  • Steps 1-2: remove resource locks from the folders/files we need to delete.
  • Steps 3-4: remove all of the old build files
  • Steps 5-6: create new versions of the build files

Deployment Project dlls cause 'type x exists in both' errors

Some reasons I can think of:

  • You have an App_Code directory in your project
  • You have a CodeFile page directive in the some page markup instead of CodeBehind

Compiler error CS0433 - The type exists in both GAC and Temporary ASP.NET files

Below is quite a story, but I think it might benefit someone else.

First of all, I opened my project inside Visual Studio 2013, and got a complaint. I followed a link from inside VS2013 (cannot find it) to a Microsoft site where it explained how to manually upgrade an MVC3 to MVC4 project. The steps I followed required manual changes to web.config.

One of the changes I made was to modify the version number of the System.Web.Mvc reference. Previously it was 3.0.0.0, and according to the guide 4.0.0.0 was the number to change to. Another step was to go into the NuGet package manager, search for ASP.NET MVC4 and install it. This downloaded version 4.0.0.1 of System.Web.Mvc, as I think that was the correct version of the time the guide was written.

Once done, I compiled the project and got into the never-ending loop of the runtime error in the question that I posted. My project was compiled against version 4.0.0.1 (which seems to be the correct version number according to a windows update). The compilation was correct, but I had the following line in my web.config:

<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

The application was compiled against 4.0.0.1, but was running and searching for 4.0.0.0 and found it in these two places:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET 
c:\Windows\Microsoft.NET\assembly\GAC_MSIL

and thew the error. I still do think this part is strange.

My solution was to modify the web.config, changing the assembly reference version as mentioned, and the binding redirects for System.Web.Mvc.

Some other sources:

  • System.Web.Mvc not functioning as expected after Windows Update
  • System.Web.Mvc broken after security update


Related Topics



Leave a reply



Submit