Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the strong name of an assembly?

Tags:

c#-4.0

I need to 'friend' a dll library that I didn't author.

I can see in the properties that it has a strong name, but how can I find out what the strong name is, so I can use it in System.Runtime.CompilerServices.InternalsVisibleTo?

like image 964
Isaac Bolinger Avatar asked Aug 12 '11 22:08

Isaac Bolinger


People also ask

How do I find a strong assembly name?

First, right click on the Assembly DLL -> Properties -> Details. Here you can find the name, version and Culture of your Assembly. It will give you the public key.

What is strong name in net Assembly?

A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature. It is generated from an assembly file using the corresponding private key.


1 Answers

To get the public key of a strong-named assembly, use the sn tool:

sn -Tp assembly.dll

This will show you the public key that you need to put in the InternalsVisibleTo attribute. If you open a Visual Studio command prompt, the sn.exe tool will already be in the path.

However, I would question what you are trying to actually achieve. If you have a compiled assembly that you did not write, adding the InternalsVisibleTo attribute to your code will let it access the internals of your code, but it wouldn't have compiled without already having friend access. If you are trying to access the internals of the other assembly, then the InternalsVisibleTo attribute will need adding to the other assembly - something which you cannot do without recompiling it..

like image 184
adrianbanks Avatar answered Oct 23 '22 06:10

adrianbanks