4

The Scenario

The vendor of GreatLib.dll deploys a custom control. It is getting used in customers Winforms application. GreatLib is strongly named and exposes some types. When these types are used as public properties in the customers forms, they are also available in the Windows Forms designer. Here is, where the hassle starts:

The designer will create items for all those types in the resource file of the form and serialize their default(?) values in those items. Since GreatLib is strongly named, the reference will include the fully qualified name for the assembly. (I think this is what Resgen does?). Such items may look as follows:

<data name="vector3Control1.value" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
    AAEAAAD/////AQAAAAAAAAAMAgAAAFRJTE51bWVyaWNzLCBWZXJzaW9uPTQuMi41MzM4LjQ4MDIxLCBD
    dWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPThkOWJmNTBlZjg1NDczNGQFAQAAABpJTE51bWVy
    aWNzLkRyYXdpbmcuVmVjdG9yMwMAAAADbV94A21feQNtX3oAAAALCwsCAAAAAAAAAAAAAAAAAAAACw==
</value>
</data>

In the Form.Designer.cs file the designer generates some code similar to this in order to read in the resource items:

this.vector3Control1.value = ((ILNumerics.Drawing.Vector3)(resources.GetObject("vector3Control1.value")));

The Problem

Vendor provides an update to GreatLib, the customer replaces the old version with the new version. But the resource file will stay the same! Hence, we either get an InvalidCastExeption on the Designer.cs code or - if the old assembly was not found anymore - a FileNotFoundException.

What is the recommended way to handle strong names in resx files?

Preventing from them completely by using

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

? Or manually transforming the base64 data on each update as suggested by HansPassant?

Community
  • 1
  • 1
Haymo Kutschbach
  • 3,322
  • 1
  • 17
  • 25
  • Just feed that string to Convert.FromBase64String(). And you'll discover that it will only work when you have version 4.2.5338.48021 of the ILNumerics.Drawing.Vector3 class referenced in your project. Odds that you do is about 1 in 48021. Zero when you ask this question. – Hans Passant Aug 13 '14 at 22:22
  • What would you recommend? Preventing from strong names, from using the designer, from creating control libraries, or from updating them? – user492238 Aug 14 '14 at 02:58
  • @Hans Passant Strange enough, this must affect basically every vendor of control libraries. And they have several lengthy knowledge base articles about that issue - no real solution though. Some provide their own update tools which probably do what you suggested. – Haymo Kutschbach Aug 14 '14 at 14:17
  • A reputable control vendor doesn't do this, they very carefully manage their version numbers and would never consider auto-generating one. – Hans Passant Aug 14 '14 at 15:29
  • Sorry, @HansPassant I cannot follow. How does this relate to the question? Reputable or not - is there an answer how to deal with strongly named assembly references embedded into resource files on updates? – Haymo Kutschbach Aug 15 '14 at 15:18
  • @HansPassant funny, I just stumbled upon this post http://stackoverflow.com/a/3769491/1215993 - sounds somehow contrary to your statement here ? Nevermind ... :) – Haymo Kutschbach Oct 30 '14 at 14:54

0 Answers0