Thursday, January 2, 2014

Referenced assembly does not have a strong name

when you are using third party .dll files or cause is an assembly is not signed with a strong name, the strong name could not be verified, or the strong name would not be valid without the current registry settings of the compute.

The strong name protects clients from unknowingly loading an assembly that has been tampered with. Assemblies without strong names should not be deployed outside of very limited scenarios.

An assembly without a strong name  cannot be loaded into the global assembly cache.


Step 1 : Run visual studio command prompt and go to directory where your DLL located.

  For Example my DLL located in D:/test/perceptiveMCAPI.dll


Step 2 : Now create il file using below command.

  D:/test> ildasm /all /out=perceptiveMCAPI.il  perceptiveMCAPI.dll
  (this command generate code library)


Step 3 : Generate new Key for sign your project.

  D:/test> sn -k mykey.snk


Step 4 : Now sign your library using ilasm command.

  D:/test> ilasm /dll /key=mykey.snk perceptiveMCAPI.il

so after this step your assembly contains strong name and signed.
just add reference this new assembly in your project and compile project its running now. 

If  your current assemble framework is 2.0 or lesser and your system contain higer framework 4.0 then strong name assemble generated in 4.0 framework. If you want to generate assemble in 2.0 frame work you change Step 4 as

D:/test>C:\Windows\Microsoft.NET\Framework\v2.0.50727\ ilasm /dll /key=mykey.snk perceptiveMCAPI.il

In this step you generate assemble in 2.0 framework


0 comments:

Post a Comment