C # Data PublicKeyToken Value

If I open Resource.resx from my C # project folder, I saw something like this:

<data name="picture" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\picture.png;System.Drawing.Bitmap, System.Drawing, 
        Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

      

What is PublicKeyToken and what value should I assign?

+3


source to share


3 answers


.NET works with assemblies; each EXE or DLL file is considered an assembly.

In order for the assembly to be recognized globally on the machine by any other .NET code that needs it (without copying it locally, of course), you can place the assemblies in the global assembly cache aka GAC.

You cannot put just any assembly in the GAC, as for security reasons, placing an assembly there requires strict aka signed input. Will not get into the assembly signing process here as it doesn't matter, but part of the signing process gets the public key. You can then use that same key for any number of assemblies, so there can be one key in an assembly, but one key can be shared by many different assemblies.

When .NET loads a strongly typed assembly, it should receive three parameters:

  • Assembly name.
  • Assembly version.
  • The public key of the assembly.

When any of these are missing or incorrect, .NET will throw an error that it cannot find the assembly.



Now for your last question: given the known name of the collector, how do you find its public key token?

Well, all system builds prior to 4.0 can be found with Windows Button+ R, then typing %windir%\assembly

and ENTER. You will be presented with a complete table of installed assemblies with name, version and key. For example, you can see that the key posted in the original question actually belongs to the System.Drawing assembly.

Due to the breaking of changes in the 4.0 framework, the location of the GAC for its assemblies has changed to %windir%\Microsoft.NET\assembly\

, and it no longer appears in the friendly list, but rather as folders and files: each assembly in the new GAC has its own, and on its behalf, you can retrieve a public token. For example, System.Web contains the following subfolder:

v4.0_4.0.0.0__b03f5f7f11d50a3a

So this means that the key is b03f5f7f11d50a3a and which you should put in the file .resx

if you have a reference to the System.Web assembly. (Note that this is the same as the System.Drawing key, but it doesn't really matter here)

+1


source


see this



Microsoft is addressing the "unlock public key" issue by using the hash of the public key of a public assembly. These hashes are referred to as public key tokens and the low 8 bytes SHA1 hash of the public assembly public key. SHA1 hashes are 160 bits (20 bytes) and the upper 12 bytes of the hash are simply thrown into this algorithm.

0


source


If you look at the properties of this link, you will notice that the Copy Local option is set to True by default.

0


source







All Articles