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
- Close Visual Studio
- Perform an iisreset
- Delete all the folders and files within the "Temporary ASP.NET Files" folder (the path is referenced in the error message)
- Delete the offending application's "obj" and "bin" folders
- Restart Visual Studio and open the solution
- 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
In Ruby, What Is the Equivalent to an Interface in C#
Seeking Clarification on Apparent Contradictions Regarding Weakly Typed Languages
Refresh Datagridview When Updating Data Source
Page.Datacontext Not Inherited from Parent Frame
Translate Rectangle Position in Zoom Mode Picturebox
ASP.NET MVC Razor: How to Render a Razor Partial View's HTML Inside the Controller Action
How to Upload Files in ASP.NET Core
How to Do Polymorphism in Ruby
How to Call (Iron)Python Code from a C# App
ASP.NET Core 6 How to Access Configuration During Startup
Best Way to Tackle Global Hotkey Processing in C#
Compare Two Datatables to Determine Rows in One But Not the Other
Raise Event in High Resolution Interval/Timer
Establish a Link Between Two Lists in Linq to Entities Where Clause