in

ASP.NET Weblogs

Russell Pooley's .NET Blog

.NET Tools, Source and Research

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.

 

Comments

 

Ledcotto said:

Hi! Just upgraded VS.NEt to 2003 version and gave me the same error on previous forms. Did the procedure you indicated and worked like magic. Thanks!

ledcotto@sympletech.com
September 15, 2003 10:12 AM
 

Bert-Jan Lappenschaar said:

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.

November 20, 2003 7:59 AM
 

Depickere Geert said:

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

Anyhow, thanks for the tip!
March 30, 2004 7:11 AM
 

Adrian Hara said:


I have the same error message in Nant, i get "invalid resX input". 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 <solution> instead of a target, but i get the same error, plus "External program failed ...resgen.exe (return code was -1163019603)".
Any help would be greatly appreciated, thanks.
April 8, 2004 4:48 AM
 

Russell Pooley said:

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.
April 8, 2004 4:32 PM
 

Adrian Hara said:


I have to apologize, i was wrong. Actually, nant output was something like:

"read in X resources from: c:\MyFile.resx "
"writing resource file: done"
"Invalid resX input"

So i assumed the faulty file was MyFile.resx, but actually, it was the NEXT file in the build order (still, would have been nice if nant told me invalid resX input at file THEFILE). With that being said, there were two types of problems: first many .resx files were empty (0 bytes), and nant can't cope with that (it's documented on the nant site), and second, as the project was started during the days of .NET beta, some .resx files were malformed, or at the very least had something like

<resheader name="Reader">
<value>System.Resources.ResXResourceReader</value>
</resheader>

in them, so no version. Anyway, i got them all done (long day) and works fine now (well, except for the fact that nant seems not to be able to cope with very long paths, but that's another issue:)). Thanks for your help and keep up the good work!

April 9, 2004 5:40 AM
 

John Adams said:

I am also having this problem in NAnt. When I copied my assembly which it "could not find" 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.
May 21, 2004 2:30 PM

Leave a Comment

(required)  
(optional)
(required)  
Add