ASP.Net
error resolution
duplicate type
DLL conflict
programming troubleshooting

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.

Browse interview questions

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:

  1. Duplicated Assemblies:
    • Including the same assembly multiple times either directly or indirectly through dependencies may lead to duplication.
  2. Incorrect Assembly Versioning:
    • Different versions of an assembly may include either the same types or types with the same name.
  3. 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 AssemblyBinding feature in the configuration file to redirect different versions to a single version. Use web.config or app.config as follows:

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track 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.

Browse interview questions