I have 2 projects in my solution:
- Assembly (Basic Library)
- Test Assembly (NUnit)
I had declared the test assembly as friends assembly in first project:
[assembly: InternalsVisibleTo ("Company.Product.Tests")]
Everything was working fine till I realised that I have forgot to setup the solution to sign my assemblies. So created a snk file and setup the visual studio project to sign the first assembly (Basic Library). Now when I compile the first project, I get following error:
Friend assembly reference 'Company.Product.Tests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.
I tried to extract the public key from my snk file using sn utility but it generates a wired binary file which I am unsure how to use. How can I fix the problem?
You need to sign both assemblies, because effectively both assemblies reference each other.
You have to put the public key in the InternalsVisibleTo attribute. For example, in Protocol Buffers I use:
The public key is retrieved by running
Alternatively, get it from the .snk file:
I think you need to put in the strong name, which would be something like "Company.Product.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=17135d9fcba0119f". I assume Company.Product.Tests is your assembly name and 17135d9fcba0119f is the public key.
Another way to resolve this problem would be not to use separate assemblies. I usually put the source code and the testing code in the same assembly. I don't know if you have any special concern that you must separate them.
You can directrly get publicKey from assembly which you interest, without magic with sn.exe