I've added a weakly named assembly to my Visual Studio 2005 project (which is strongly named). I'm now getting the error:
"Referenced assembly 'xxxxxxxx' does not have a strong name"
Do I need to sign this third-party assembly?
This question is related to
c#
visual-studio
visual-studio-2005
assemblies
strongname
First make sure all nuget packages are at the same version across all projects in your solution. e.g. you dont want one project to reference NLog 4.0.0.0 and another project to reference NLog 4.1.0.0. Then try reinstalling nuget packages with
Update-Package -reinstall
I had 3 3rd party assemblies that were referenced by my assembly A and only 2 were included in References by my assembly B which also referenced A.
The missing reference to the 3rd party assembly was added by the update package command, and the error went away.
For me, the problem was a NuGet package without a strong name. The solution was to install StrongNamer from NuGet, which automatically adds a strong name to all referenced assemblies. Just simply having it referenced in the project fixed my issue.
Expand the project file that is using the project that does not "have a strong name key" and look for the .snk
file (.StrongNameKey).
Browse through to this file in Windows Explorer (just so that you know where it is).
Back in Visual Studio in the project that does not "have a strong name key", do
<Browse>
to the .snk
file you found earlierThat should do the trick. This solved a problem for me for one project using a form inside another project in the same solution.
I hope it helps.
I had this issue for an app that was strongly named then had to change it in order to reference a non-strongly named assembly, so I unchecked 'Sign the assembly' in the project properties Signing section but it still complained. I figured it had to be an artifact somewhere causing the problem since I did everything else correctly and it was just that. I found and removed the line: [assembly: AssemblyKeyFile("yourkeyfilename.snk")] from its assemblyInfo.cs file. Then no build complaints after that.
Old question, but I'm surprised no one has mentioned ilmerge yet. ilmerge is from Microsoft, but not shipped with VS or the SDKs. You can download it from here though. There is also a github repository. You can also install from nuget:
PM>Install-Package ilmerge
To use:
ilmerge assembly.dll /keyfile:key.snk /out:assembly.dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /ndebug
If needed, You can generate your own keyfile using sn (from VS):
sn -k key.snk
Situation: You had project A,B,C,D in solution X,Y
Project A, B, C in X Project A, C, D in Y
I need use project C in project A, but later i dont use. In bin Debug project A had C.dll.
If I compile solution X, all good ( in this solution i delete reference A -> C. ), but in solution Y I get this problem.
Solution is delete C.dll in project A bin Debug
Removing the "Sign the assembly" check mark under the "Signing" tab works as @Michal Stefanow said.
Add here is the simplest way to sign your own files and/or other people's files. You just need to add this line under the "Post-build event command line":
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\signtool.exe" sign /f "$(ProjectDir)\YourPfxFileNameHere.pfx" /p YourPfxFilePasswordHere /d "Your software title here" /du http://www.yourWebsiteHere.com /t http://timestamp.verisign.com/scripts/timstamp.dll /v "$(BaseOutputPath)$(TargetFileName)"
You can sign other people's files or your own files and as many as you want.
Situation: You had project A,B,C,D in solution X,Y
Project A, B, C in X Project A, C, D in Y
I need use project C in project A, but later i dont use. In bin Debug project A had C.dll.
If I compile solution X, all good ( in this solution i delete reference A -> C. ), but in solution Y I get this problem.
Solution is delete C.dll in project A bin Debug
Removing the "Sign the assembly" check mark under the "Signing" tab works as @Michal Stefanow said.
Add here is the simplest way to sign your own files and/or other people's files. You just need to add this line under the "Post-build event command line":
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\signtool.exe" sign /f "$(ProjectDir)\YourPfxFileNameHere.pfx" /p YourPfxFilePasswordHere /d "Your software title here" /du http://www.yourWebsiteHere.com /t http://timestamp.verisign.com/scripts/timstamp.dll /v "$(BaseOutputPath)$(TargetFileName)"
You can sign other people's files or your own files and as many as you want.
You can use unsigned assemblies if your assembly is also unsigned.
Signing the third party assembly worked for me:
http://www.codeproject.com/Tips/341645/Referenced-assembly-does-not-have-a-strong-name
EDIT: I've learned that it's helpful to post steps in case the linked article is no longer valid. All credit goes to Hiren Khirsaria:
Run visual studio command prompt and go to directory where your DLL located.
For Example my DLL is located in
D:/hiren/Test.dll
Now create the IL file using the command below.
D:/hiren> ildasm /all /out=Test.il Test.dll
(this command generates the code library)
Generate new key to sign your project.
D:/hiren> sn -k mykey.snk
Now sign your library using ilasm
command.
D:/hiren> ilasm /dll /key=mykey.snk Test.il
sn
ildasm
and ilasm
sn –k Cool.Library.snk
to create a new key pairildasm Cool.Library.dll /out:Cool.Library.il
to disassemble the librarymove Cool.Library.dll Cool.Library.unsigned.dll
to keep the original library as a back-upilasm Cool.Library.il /dll /resource=Cool.Library.res /key=Cool.Library.snk
to reassemble the library with a strong namepowershell -command "& {[System.Reflection.AssemblyName]::GetAssemblyName($args).FullName} Cool.Library.dll"
to get the assembly fully qualified name. You will need this bit if you have to reference the DLL in external configuration files like web.config or app.config.Old question, but I'm surprised no one has mentioned ilmerge yet. ilmerge is from Microsoft, but not shipped with VS or the SDKs. You can download it from here though. There is also a github repository. You can also install from nuget:
PM>Install-Package ilmerge
To use:
ilmerge assembly.dll /keyfile:key.snk /out:assembly.dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /ndebug
If needed, You can generate your own keyfile using sn (from VS):
sn -k key.snk
You can use unsigned assemblies if your assembly is also unsigned.
I was searching for solution to the very same problem and un-ticking "Sign the assembly" option works for me:
(as you may notice screenshot comes from VS2010 but hopefully it will help someone)
Signing the third party assembly worked for me:
http://www.codeproject.com/Tips/341645/Referenced-assembly-does-not-have-a-strong-name
EDIT: I've learned that it's helpful to post steps in case the linked article is no longer valid. All credit goes to Hiren Khirsaria:
Run visual studio command prompt and go to directory where your DLL located.
For Example my DLL is located in
D:/hiren/Test.dll
Now create the IL file using the command below.
D:/hiren> ildasm /all /out=Test.il Test.dll
(this command generates the code library)
Generate new key to sign your project.
D:/hiren> sn -k mykey.snk
Now sign your library using ilasm
command.
D:/hiren> ilasm /dll /key=mykey.snk Test.il
I have written a tool to automatically strong-name sign assemblies including ones you do not have the source code for or projects that have been abandoned. It uses many of the techniques described in the answers in a simple way without any of the flaws or drawbacks of existing tools or dated instructions.
http://brutaldev.com/post/2013/10/18/NET-Assembly-Strong-Name-Signer
Hope this helps out anyone that need to sign a third party assembly without having to jump through hoops to get there.
I was searching for solution to the very same problem and un-ticking "Sign the assembly" option works for me:
(as you may notice screenshot comes from VS2010 but hopefully it will help someone)
I have written a tool to automatically strong-name sign assemblies including ones you do not have the source code for or projects that have been abandoned. It uses many of the techniques described in the answers in a simple way without any of the flaws or drawbacks of existing tools or dated instructions.
http://brutaldev.com/post/2013/10/18/NET-Assembly-Strong-Name-Signer
Hope this helps out anyone that need to sign a third party assembly without having to jump through hoops to get there.
Expand the project file that is using the project that does not "have a strong name key" and look for the .snk
file (.StrongNameKey).
Browse through to this file in Windows Explorer (just so that you know where it is).
Back in Visual Studio in the project that does not "have a strong name key", do
<Browse>
to the .snk
file you found earlierThat should do the trick. This solved a problem for me for one project using a form inside another project in the same solution.
I hope it helps.
For me my issue was that I had two of the same NuGet Packages installed with different Versions.
There is a NuGet package named StrongNamer by Daniel Plaisted that seems to do the trick.
Is the simplest solution that I've found so far.
There are also a number of other NuGet packages to fix the strong naming problem such as Brutal.Dev.StrongNameSigner by Werner van Deventer, but I have not tested that one or any of the others.
First make sure all nuget packages are at the same version across all projects in your solution. e.g. you dont want one project to reference NLog 4.0.0.0 and another project to reference NLog 4.1.0.0. Then try reinstalling nuget packages with
Update-Package -reinstall
I had 3 3rd party assemblies that were referenced by my assembly A and only 2 were included in References by my assembly B which also referenced A.
The missing reference to the 3rd party assembly was added by the update package command, and the error went away.
There is a NuGet package named StrongNamer by Daniel Plaisted that seems to do the trick.
Is the simplest solution that I've found so far.
There are also a number of other NuGet packages to fix the strong naming problem such as Brutal.Dev.StrongNameSigner by Werner van Deventer, but I have not tested that one or any of the others.
For me my issue was that I had two of the same NuGet Packages installed with different Versions.
For me, the problem was a NuGet package without a strong name. The solution was to install StrongNamer from NuGet, which automatically adds a strong name to all referenced assemblies. Just simply having it referenced in the project fixed my issue.
I had this issue for an app that was strongly named then had to change it in order to reference a non-strongly named assembly, so I unchecked 'Sign the assembly' in the project properties Signing section but it still complained. I figured it had to be an artifact somewhere causing the problem since I did everything else correctly and it was just that. I found and removed the line: [assembly: AssemblyKeyFile("yourkeyfilename.snk")] from its assemblyInfo.cs file. Then no build complaints after that.
sn
ildasm
and ilasm
sn –k Cool.Library.snk
to create a new key pairildasm Cool.Library.dll /out:Cool.Library.il
to disassemble the librarymove Cool.Library.dll Cool.Library.unsigned.dll
to keep the original library as a back-upilasm Cool.Library.il /dll /resource=Cool.Library.res /key=Cool.Library.snk
to reassemble the library with a strong namepowershell -command "& {[System.Reflection.AssemblyName]::GetAssemblyName($args).FullName} Cool.Library.dll"
to get the assembly fully qualified name. You will need this bit if you have to reference the DLL in external configuration files like web.config or app.config.Source: Stackoverflow.com