Windows forms resx troubles.

After spending all of about two days trying to complete a build system for where I work, I came across a rather strange problem.

If you create a C# windows application project in Visual Studio .NET 2002, check the .resx file for the Form1.cs, you will find a couple of lines that refer to what version of the System.Windows.Forms assembly to use for the resx reader and writer. These will look like the following:

<resheader name="Reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value
>
</resheader>

<resheader name="Writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value
>
</resheader>

Now as you can probably see the version stated is 1.0.3102.0, this doesn't seem to cause VS.NET any problems, but as soon as you use NAnt the resgen application will throw errors regarding an invalid resx input.

To solve the problem, just draw a button on the form and delete it, this will then recreate the resx file, and it will now point to the correct version.

<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value
>
</resheader>

<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value
>
</resheader>

You may well ask that this problem will never arise since if you create a form you are going to add buttons and other controls on the form anyway so the resx will regenerate, the problem shows itself if you delete the resx for an existing form and then get  the IDE to recreate it. It will recreate it against the old version so you will need to add a button and then delete it to assign it the correct version.

Not sure if VS.NET 2003 has this same issue, if someone finds out then let me know.

 

7 Comments

  • I had the same error message in my Nant build scripts. After searching for days what could cause this problem I eventually figured it out:

    there was a reference to a strong named assembly in the resource file (a reference to explorerbar.dll, that has the explorerbar control). Reason it didn't work was that on the build machine, this file only existed as a copy in the output directory (which I thought should be enough), and didn't exist in the GAK. After putting the file in the GAK, everything worked fine.



  • Instead of adding &amp; removing a button, you can also set the &quot;Localizable&quot; property to false and then back to true... This also does the trick.



    Anyhow, thanks for the tip!



  • I have the same error message in Nant, i get &quot;invalid resX input&quot;. The thing is, i just checked the version, and it is 1.0.3300.0, for all resources. I tried adding and removing a button or whatever, nothing changed. More, even though all files have reader version of 1.0.3300.0, some of them build fine, and i only get an error at the seventh file (or something), but i suspect there could be more errors (i have no way of knowing, the build process stops).

    As you said, in vs.net the project builds fine, in nant, it doesn't. I even tried using &lt;solution&gt; instead of a target, but i get the same error, plus &quot;External program failed ...resgen.exe (return code was -1163019603)&quot;.

    Any help would be greatly appreciated, thanks.

  • If you try to manually resgen each resx file you will be able to find out which one is causing the error. Once you have found the offending file send it to me at russell@nospamvsdotnet.co.uk make sure you remove the nospam from the email address and I will have a look.

  • I am also having this problem in NAnt. When I copied my assembly which it &quot;could not find&quot; into the directory where resgen.exe is, the problem went away. Bizarre to say the least. This interesting thing is that there is no reference to this assembly in the resx file at all.

  • I just had a simila issue using resgen directly. It turned out that the .resx file contained an extra attribute 'Type' associated with Infralgistics controls. I guess this is breaking resgen parser for some reason.

    Regards

    Dave

    e.g.



  • I got this problem with visual studio 2005 and fixed it with you instructions, thank you

Comments have been disabled for this content.