"An assembly with the same simple name has already been imported" error without duplicate reference
Asked Answered
O

11

25

I'm getting the following error:

error CS1704: An assembly with the same simple name 'Interop.xxx.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.

Everything I've seen says that I am referencing two assemblies with the same name and I need to remove one of them. However, I've checked and I'm only referencing it once.

This also only happens when I'm using msbuild to build from the command line on my dev box. If I build through Visual Studio or do a clean build on our CI server I don't see this error.

I've tried completely removing all of my source and building from scratch to more closely resemble the build machine but no luck.

Osyth answered 1/7, 2010 at 18:31 Comment(2)
Post the csc.exe command line for that project.Orff
#28730600Shellishellie
O
8

So it looks like I can't read today!
The project had a reference to the Interop and a COM reference that generated the "same" interop. So there were two and I just didn't search very well. I still don't understand why it worked in other places but this did fix it.

Osyth answered 1/7, 2010 at 20:24 Comment(1)
+1 - Thanks - this error just popped up on me out of the blue today, and I had exactly the same problem.Psittacine
V
5

In my case the duplicate entry was caused by a NuGet package reference and a direct file reference to the same assembly in the packages folder. I am not sure how the project got into this state, but unloading the project and searching the XML file for the offending assembly name resolved the issue for me.

Note that in my case this started happening after updating a NuGet package to a newer version with no other changes to the project, so this maybe caused by a bug in NuGet.

Veach answered 5/2, 2020 at 7:11 Comment(1)
My case was similar: a dll, that previously was referenced by NuGet, was added to the solution as project (and updated there to a newer version). Afterwards, CS1704 occurred for no apparent reason. But there still was a transitive dependency to the old version of the dll which always pulled it and provoked the error!Roop
M
4

In the Error List window, the project that was triggering this error was listed in the Project column. I got around the error by doing the following:

  • I unloaded the listed project (right-click => Unload Project)
  • Opened the XML for edit (right-click the unloaded project => Edit {ProjectName.csproj}).
  • Searched for the offending .dll, and noticed it was listed multiple times in the XML
  • Removed the entire Reference tag related to the offending dll, and did so for every copy of the reference except the first one listed

The reason it was listed multiple times was because several referenced libraries used that dll. This shouldn't be a problem, in and of itself, so I'm not sure what caused this error to suddenly pop up for me. I'll update this answer if I figure that out.

Mme answered 6/4, 2018 at 20:27 Comment(0)
B
2

If this is a web project, are there any strong-named references to the other version there? Those won't show up as a project dependency, but will cause a run-time error like you describe. Hope that helps

Bequeath answered 1/7, 2010 at 19:39 Comment(0)
A
2

I had this problem but in my case, I had an old copy placed in the current folder for the EXE loading my component, that was loaded together with the current one, that was loaded by hand from my projects folder. Deleting that old copy solved my problem.
I used Debug > Windows > Modules window to see which modules were loaded at that time and that solved my problem.

Ambition answered 3/3, 2016 at 14:49 Comment(0)
C
2

For those developing UWP projects that have project references that include specifically the Microsoft.Windows.SDK.Contracts nuget package (or other dependencies that reference it), this is a common error when the version of the SDK contracts is targeting a different version of the runtime to how your project is configured.

For instance, when targeting Windows 10, version 1903: UWP Runtime Targeting

Any dependencies or reference projects should target or at least support the same runtime version.

it is common thought process to update all NuGet packages when a new stable version is available, but this is not always a helpful practise on its own. Just because a new stable version of a package is available does not mean that you should or that you can easily use that version.

Even though this package for SDK contracts has a stable update, it is not compatible with my main project configuration, Nuget does not know this so it allows the update.

Windows SDK Contracts

This package is specifically designed to provide windows dlls for project types that DO NOT have windows platform targeting support, it copies the same dlls that are included by the UWP targeting config. By installing later versions of the package the references from the satellite project will be included in the output along with those provided due to platform targeting, ultimately causing OPs error.

There are similar SDK and targeting packs for Windows IoT Device Runtimes, this information should help you identify and resolve those issues if you get stuck on this issue as my team often does :)

Consolute answered 21/7, 2020 at 2:14 Comment(0)
D
1

For others facing the same as me: if building via command line using property AssemblyName, it will overwrite all assemblies generated by all solution projects - in other words, you will end up with (N -1) assemblies named the same where N is the no. of projects - the startup one (which generally will generate an exe).

This happens because all build command line properties are global and overwrite any project-specific setting. See this and this.

From the msdn link mentioned above:

Global properties are properties that are set by using the /property switch on the command line, or properties that are set by the integrated development environment (IDE) before a project is built. These global properties are applied to all projects that are built by using this Engine.

In my specific case, where Jenkins is the CI tool, I ended up adding a windows batch command at the end to rename the .exe only to what I originally intended when passing the AssemblyName parameter.

Dett answered 4/5, 2017 at 11:55 Comment(0)
C
1

Try this instead: remove Interop.xx.dll from the reference section in Solution Explorer and Rebuild the project

Cyclonite answered 20/5, 2018 at 21:2 Comment(1)
Updating nuget packages has caused me untold aeons of pain and heartacheMercuric
C
1

In my case, the issue was on wrong characters in the ProjectReference section of my csproj file.

Background

I have a project that references another library I maintain, which I publish as a NuGet package.

Whenever I make changes to my library, I usually reference the local dll in my project to test and make sure everything looks good before I publish the library as a NuGet package.

When testing, I just comment out the PackageReference line and uncomment the ProjectReference one so it references my local dll, like so:

<ProjectReference Include="..\..\my-class-library\MyClassLibrary.csproj" />
<!--<PackageReference="MyClassLibrary" Version="2.0.1"/>-->

Root cause

I had the slashes inverted, so I was using / rather than \ in the path, like so:

<ProjectReference Include="../../my-class-library/MyClassLibrary.csproj" />

Once corrected, the issue went away.

Calves answered 16/11, 2022 at 16:55 Comment(0)
O
0

In our case this error was shown when we had a duplicate reference inside the .csproj file (although I have no idea how this happened).
The difference to an already posted answer is that, in our case, one was a project reference and another one was direct binary reference to a dll.
Once we removed one of those, project correctly compiled.

Octosyllable answered 25/1, 2022 at 12:5 Comment(0)
A
0

None of the above answers worked for me.

I'm using an old MVC web application that compiles just fine with the "offending" dll.

The error would come up when IIS/ASP.Net would compile the "temporary internet files", and at first glance didn't tell me much. The dll in question was only referenced in place in the project, and it compiled fine, so why was IIS/ASP.Net complaining?

After a few hours I figured out the IIS/ASP.Net error did indeed have the info I required to solve it. The CSC compile line scrolls far to the right, and it's not obvious in your browser you can scroll and scroll and scroll...

Copied that multi-page CSC compile line out to notepad with wordwrap on and searched on the dll in question, did a search, and found there's a plugin in this application that uses a much much older version of the offending dll. IIS/ASP.Net knew that, and complained. Visual Studio had no clue.

Hopefully this helps someone down the road in Stackoverflow land.

Arissa answered 28/2 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.