Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly generation failed - Referenced assembly does not have a strong name. Why doesn't other solutions work?

This is a classic problem, which has numerous solutions described. However, none of them seem to work for me.

I am using the Report.NET library in a SharePoint solution. Adding the Reports.dll as a reference and compiling results in the error message "Assembly generation failed - Referenced assembly 'Reports' does not have a strong name." My project, however, has a key.snk linked in the project properties. So I try to disassemble, sign and reassemble the dll with this key file, as described elsewhere:

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>ildasm Reports.dll /out:Reports.il

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>ilasm Reports.il /dll /resource=Reports.res /key=..\key.snk

<output removed for brevity>

Class 95
Class 96
Method Implementations (total): 1
Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved
Writing PE file
Signing file with strong name
Operation completed successfully

I end up with a new Reports.dll timestamped to now. Adding this as a reference to my project and building, though, gives the same error message as before. The properties of the "Reports" reference displays "Strong Name: False".

Not to be discouraged by a bit of trouble, I attempt to re-sign the assembly using the strong naming utility:

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>sn -R Reports.dll ..\key.snk

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly 'Reports.dll' successfully re-signed

It might be worth noting that running the SN utility fails with the error message "Reports.dll does not represent a strongly named assembly" when running it before the disassemble/sign/reassemble process.

However, when running it after disassembly/signing/reassembly, I still get the original error message when re-adding it to Visual Studio.

like image 249
Geir Smestad Avatar asked Feb 22 '12 08:02

Geir Smestad


People also ask

How do you fix referenced assembly does not have a strong name error?

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.

How is a strongly named assembly different from one that isn't strongly named?

Strong naming your assembly allows you to include your assembly into the Global Assembly Cache (GAC). Thus it allows you to share it among multiple applications. Strong naming guarantees a unique name for that assembly. Thus no one else can use the same assembly name.

How do you know if an assembly is strongly named?

To determine if an assembly is strong-typed, use the Strong Name Tool from Microsoft (http://msdn.microsoft.com/en-us/library/k5b5tt23(v=vs.71).aspx) by running the 'sn.exe -v <assembly>' command. You may need to download one of the Windows SDK packages to get access to this tool.

What makes a strong named assembly in .NET framework?

What makes a strong-named assembly? A strong named assembly is generated by using the private key that corresponds to the public key distributed with the assembly, and the assembly itself. The assembly includes the assembly manifest, which contains the names and hashes of all the files that make up the assembly.


2 Answers

I just solved this problem in vs 2010 using this:

Project Properties -> Signing -> uncheck Sign the assembly checkbox
like image 161
Oleg Guchashvili Avatar answered Oct 20 '22 19:10

Oleg Guchashvili


I would suggest that if, after you have unambiguously signed the Reports.dll correctly from the command line, VS still says that that dll is unsigned; then it must be referencing the wrong file.

If you want to be really paranoid and double-check the strong-naming after signing, load Reports.dll into ildasm (you have to double-click the manifest node in the tree and scroll down to find the .publickey section). Or for ease just open it in ILSpy.

After signing reports.dll; open your referencing project's proj file as an XML document (if you have the VS PowerCommands you can right-click and 'Edit Project File'; otherwise you can unload the project and then open it in VS using the 'Open With' command from the Open File dialog) and verify that the reference to the dll is indeed the correct path. If it's not, correct it and reload the project.

like image 21
Andras Zoltan Avatar answered Oct 20 '22 21:10

Andras Zoltan