views:

105

answers:

2

This is probably really easy, but I'm stumped (and I'm a noob with c#). I have 3 assemblies that reference each other (for example, registering for notification of a delegate method, or calling a public method), all of which compile fine until I try to sign them with a strong name. Then I can't compile any of them, since the other two don't have a strong name. What am I missing? I've created a strong name file for all three, but can't include the snk and compile them.

+4  A: 

If you have created one snk file that you want to use on all three of them choose: Add Existing Item from the context menu on the projects.

Browse to the snk file and then choose "Add as link" by clicking on the arrow next to the Add button.

Then in your project properties make sure in the tab Signing check the "Sign the assembly" checkbox and then select the keyfile you just added to your project.

That should do the trick.

Anton
+1. Since you seem to know this stuff and I'm curious, are there any downsides to using the same key for all of them?
Skurmedel
Not that I know of at the moment. Actually loads of related Microsoft assemblies have the same PublicKeyToken (you can check this in your Global Assembly Cache) indicating they have been signed with the same key file as well, iirc.
Anton
That's good to know, a bit tedious if you have 5 assemblies and you generate 5 keys in vain :)
Skurmedel
Worked like a charm. Thanks so much!
Shawn
+2  A: 

A strongly named assembly can only reference other strongly named assemblies.

When you reference a strong-named assembly, you expect to get certain benefits, such as versioning and naming protection. If the strong-named assembly then references an assembly with a simple name, which does not have these benefits, you lose the benefits you would derive from using a strong-named assembly and revert to DLL conflicts. Therefore, strong-named assemblies can only reference other strong-named assemblies.

Quoted from MSDN.

Skurmedel