Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to assembly without strong name

Is there a way to reference a library without a strong name? When I add a reference to the assembly in references and rebuild solution everything is fine, but when I call the class from this assembly solution it doesn't build.

Output says that referenced assembly should have strong name. What is the best solution? Strong naming library is not preferable.

like image 652
xwrs Avatar asked Jun 16 '11 11:06

xwrs


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.

Should I strong name my assemblies?

You should strong name your open-source . NET libraries. Strong naming an assembly ensures the most people can use it, and strict assembly loading only affects . NET Framework.

How do you tell 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.

Why a strongly named assembly is required?

"Strong Name : Indicates that the reference has been signed with a key pair." If your current project's assembly is signed, then all your reference assemblies must also be signed. Failure to do so will result in this error.


1 Answers

I think the problem you have here is that the assembly you are trying to add the reference from is being signed with a strong name but the assembly you are trying to reference is not signed. A strong-named assembly can only reference other strong-named assemblies.

Either sign the assembly you are referencing or don't sign the assembly that is referencing it.

The reason why the error only appears when you actually call the class is because the compiler will strip out the reference in the compiled output if there is no code actually invoking the referenced assembly.

If it's the case that you really can't either add a strong name to the one being referenced, or remove the strong name from the one doing the referencing (sorry long-winded) then you are going to have to look at binding the class at runtime via reflection and then accessing it via a common base or interface - not ideal at all; or even worse actually invoking it via reflection, or dynamic.

like image 121
Andras Zoltan Avatar answered Sep 28 '22 04:09

Andras Zoltan