First of all, I doubt that it is really needed — please see my comment to the question.
But let's assume you really need this information. This is easy to do. First of all, you need to get the entry assembly. This is the application assembly you were asking about. When you do it, you need to get its
AssemblyName
object.
using System.Reflection;
Assembly entryAssembly = Assembly.GetEntryAssembly();
AssemblyName name = entryAssembly.GetName();
The
AssemblyName
object found carries all the information on the assembly signature, such as:
https://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.getpublickeytoken%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.getpublickey%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.keypair%28v=vs.110%29.aspx[
^].
See also:
https://msdn.microsoft.com/en-us/library/system.reflection.assembly.getentryassembly%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/y3bk16ya(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/System.Reflection.AssemblyName%28v=vs.110%29.aspx[
^].
[EDIT]
Please pay attention for our discussion in the comments to the question with Andy Lanng, who reminded me an
alternative possibility,
friend assemblies:
https://msdn.microsoft.com/en-us/library/ms177208.aspx[
^],
https://msdn.microsoft.com/en-us/library/0tke9fxk.aspx[
^],
https://msdn.microsoft.com/en-us/library/bb384966.aspx[
^],
https://msdn.microsoft.com/en-us/library/bb385180.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.assemblyname.aspx[
^].
It can be much better for maintainability of your code. Open the first article referenced above and pay attention that you can give the string representation of the
strong name of the assembly to the
InternalsVisibleTo
attribute parameter. That said, you can open up internals only to the assembly you tag with world-unique strong name, based on
public-key cryptography, which makes faking this limitation
cryptographically infeasible. Also pay attention for the property
AllowMultiple
set to true for this attribute, so you can apply this assembly-level attribute to your library assembly, allowing more than one referencing assemblies. Also note that you limit the set of the assemblies having access to library internals to the
referencing assemblies, not just the entry assemblies, which gives you more control. Take a closer look:
https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx[
^].
See also:
https://en.wikipedia.org/wiki/Public-key_cryptography[
^],
https://en.wikipedia.org/wiki/Computational_complexity_theory[
^].
Another alternative you can consider could be
private assemblies:
https://msdn.microsoft.com/en-us/library/windows/desktop/ff951638%28v=vs.85%29.aspx[
^].
Even though these alternatives are not exactly what you were asking about, they could be more adequate to what you really need.
—SA