Search code examples
c#visual-studioresourcesportingsystem.drawing

Why do I need to change "internalKeyToken" to "PublicKeyToken" in my resx file?


I have moved a C# solution file from VS 2005 to VS 2010, and on a new computer. One issue I encountered is that the original version of the resource file mixed PublicKeyToken and internalKeyToken like so:

<data name="NAME" type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>PATH;System.Drawing.Bitmap, System.Drawing, 
  Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

and

<data name="NAME" type="System.Resources.ResXFileRef, System.Windows.Forms">
  <value>PATH;System.Drawing.Bitmap, System.Drawing,
  Version=2.0.0.0, Culture=neutral, internalKeyToken=b03f5f7f11d50a3a</value>
</data>

This file was generated by Visual Studio 2005 via use of the designer, though I'm editing it by hand to change instances of internalKeyToken to PublicKeyToken. Not doing so gives me a compiler error:

Error   19  Could not load file or assembly 'System.Drawing, 
Version=2.0.0.0, Culture=neutral' or one of its dependencies. 
The system cannot find the file specified. Line 225, position 5.

So, I am wondering:

  1. Why did Visual Studio 2005 somewhat arbitrarily switch between internalKeyToken and PublicKeyToken? The files are all in the same format.
  2. Why did that work before but now gives a "Could not load file" error? What has changed?

Solution

  • My crystal ball says that you had an out-of-control Search + Replace. You replaced "public" with "internal" and accidentally modified the .resx file as well. Just fix it or restore from source control.

    Even the top dogs make this mistake.