'How to debug/fix 'An assembly with same simple name' has already been imported
I've used nuget install-package to install a package (let's call it PackageA) into a project. After install, my project.json file looks like this:
{
"dependencies": {
"PackageA": "1.1.15"
},
"frameworks": {
"net45": {}
},
"runtimes": {
"win": {}
},
"supports": {}
}
Now, PackageA has an indirect dependency on PackageC. Nuget successfully installs the package, but when I compile I get an error CS1704 "An assembly with the same simple name 'PackageC' has already been imported. Try removing one of the references (...\PackageC.dll) or sign them to enable side-by-side."
Strong signing is not an option, per the folks who tell me what to do.
If I delete the reference suggested by the CS1704 message, then I get a compilation error stating "Could not copy the file ...\PackageC.dll" because it was not found."
If I change the PackageA version to a floating version "*", then Nuget complains that it can't resolve a bunch of dependencies. (I eventually want to use floating versions.)
{
"dependencies": {
"PackageA": "*"
},
"frameworks": {
"net45": {}
},
"runtimes": {
"win": {}
},
"supports": {}
}
If I then overspecify my project.json, that error goes away and the CS1704 returns.
{
"dependencies": {
"PackageA": "*",
"PackageB": "*",
"PackageC": "*"
},
"frameworks": {
"net45": {}
},
"runtimes": {
"win": {}
},
"supports": {}
}
Some additional notes to make this more perplexing:
- All package dependencies also use floating versions.
- I've tried clearing the nuget cache (
nuget locals all -clear) to no avail. - Package install and compilation works fine if I ditch project.json and nuget automatic restore. Unfortunately, this isn't an option either.
- This was previously working. No idea what changed that broke it.
What can I do to debug / fix this?
Solution 1:[1]
What can I do to debug / fix this?
This error points out that two references have the same assembly identity because the assemblies in question lack strong names, they were not signed, and thus the compiler has no way of distinguishing between them in metadata. Thus, the run time ignores the version and culture assembly name properties. You can refer to Compiler Error CS1704 for more detail.
To resolve this issue, you can try to provide a strong name for them, if this option is not your choice, you can also try to remove the redundant reference or rename one of the references.
You can check the project file to make sure whether the "PackageC" has been imported (Right click project->Unload project->Edit project).
Solution 2:[2]
What can I do to debug / fix this?
In some cases with older code (and no duplicate assembly references to be found) this error will happen in one version of Visual Studio but not another. If you have multiple versions of VS installed, launch a newer one and then from the File menu open the solution and build it. If the error goes away, you have a couple different options for making the change permanent:
If you're feeling particularly bold, you can manually edit the solution (.sln) file to have it always open the project in the working VS version. (To find the version number to use, create a throwaway project and examine the generated solution file.) For example:
VisualStudioVersion = 12.0.40629.0
might become
VisualStudioVersion = 15.0.28307.572
However, the above can be somewhat risky since file formats may have changed between VS versions. So the other approach would be to recreate your project in the working VS version and copy the code over.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Leo Liu-MSFT |
| Solution 2 | Tawab Wakil |
