.net - Added a strong named assembly, but it is looking for unsigned assembly

618 views Asked by At

So, I have two projects... One is a big class library, and the other is a big simulator project.

Originally during testing the assemblies were not strong-named, but now that I need COM visibility, I need to strong name them (I need this quick, and it is easier to make them COM visible rather than deal with the CLI).

I generated a .snk and added it to the properties of each of the projects, the class library compiles just fine and outputs the .dll just fine. I added this .dll as a reference in the simulator project, but now the simulator project is giving me the following error:

The type "DynamicsControl" is defined in an assembly that is not referenced. You must add a reference to assembly "DynamicsControl, Version=0.4.3.0, Culture=neutral, PublicKeyToken=null"

The type DynamicsControl does exist in the class library (I verified), but it is claiming I am not loading the correct assembly. I believe it is the PublicKeyToken=null that is causing the issue (as my assembly would have a public key).

When I do sn -Tp DynamicsControl.dll (the one in the location I am referencing), it outputs the private and public key, so I know it has a proper signature.

What step am I missing? Do I have to add the assembly to the GAC? Do I manually have to add the public key?

1

There are 1 answers

1
Adarsh Shah On

Yes you need to specify the publicKeyToken for a strong named assembly otherwise it will look for unsigned version of the assembly. You can find out the public key token either by adding the assembly to GAC (and you will see it there) or by using the steps mentioned in the this link

If you want to read more about strong name and dll hell you can go to this URL .

Strong name prevents from dll hell which means you can have multiple versions of same assembly.

To your other question you don't have to add the assembly to GAC but CLR will look for the assembly first in GAC and then other places. Also, you don't have to add the key manually. If you remove the reference and add it back using the signed assembly it should automatically take the key.