ASP.Net error The type 'foo' exists in both temp1.dll and temp2.dll
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
ASP.NET developers can sometimes encounter a perplexing error message that reads: "The type 'foo' exists in both 'temp1.dll' and 'temp2.dll'." This error can be daunting, especially if you're not familiar with the underlying causes. In this article, we'll delve into the possible reasons behind this issue, explore the mechanisms that lead to it, and provide strategies for resolving it effectively.
Understanding the Error
The ASP.NET error message "The type 'foo' exists in both 'temp1.dll' and 'temp2.dll'" typically indicates a type conflict within your application or library references. This occurs when two different assemblies (DLLs) in your project contain a type with the same fully qualified name, causing ambiguity for the compiler or runtime. This clash prevents the project from determining which assembly's type to use, leading to a compilation or runtime error.
Root Causes
Understanding the root causes of this error can aid in devising appropriate solutions:
- Duplicated Assemblies:
- Including the same assembly multiple times either directly or indirectly through dependencies may lead to duplication.
- Incorrect Assembly Versioning:
- Different versions of an assembly may include either the same types or types with the same name.
- Type Conflict in Multiple Projects:
- If you are building multiple projects within the same solution, similar namespaces can result in conflicts if not managed correctly.
Strategies for Resolution
Here are some steps you could take to resolve this occurrence effectively:
- Examine References:
- Navigate through your project's references in Visual Studio. Ensure that you’re not accidentally referencing two assemblies that contain the same types.
- Use Aliases:
- If the same type exists in different assemblies for a valid reason, specifying aliases could help:
- Check NuGet Packages:
- Verify the versions of your NuGet packages. Ensure no conflicting libraries are being used by the references your project imports.
- Clean and Rebuild:
- Sometimes, a simple solution is the best fit. Cleaning and rebuilding your solution may resolve these discrepancies.
- Version AssemblyBinding:
- Utilize the
AssemblyBindingfeature in the configuration file to redirect different versions to a single version. Useweb.configorapp.configas follows:
Related reading
- ASP.NET HttpContext is null in 4.6.1 sample project
- ASP.NET MVC - Find Absolute Path to the App_Data folder from Controller
- ASP.NET MVC - Getting QueryString values
- ASP.NET MVC Custom Validation by DataAnnotation
- ASP.NET strange compilation error
- Assembly binding redirect does not work
- ASP.NET MVC Global Variables
- ASP.NET MVC Hidden field value does not get rendered using HtmlHelper.Hidden

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.