Question

I'm trying to translate an application from English to Spanish, using the .resx files to do so.

I'm using a very small application that's been built to go through every .resx file in a directory and create a new .resx file in another location, which will have the required text (such as that from labels or buttons) translated.

There's a piece of my code that looks like this

RReader = New ResXResourceReader(lResxInputFile)
RReader.UseResXDataNodes = False
Dim client As TranslateClient = New TranslateClient("http://www.mywebsite.com")
For Each entry As DictionaryEntry In RReader
    ...
Next entry

NOTE: lResxInputFile is a string with the location of the original .resx, such as "C:\MyProject\Forms\MyForm.resx"

This code works well most of the time and the .resx files are being duplicated and translated correctly for most forms.

However, for some of them an ArgumentException is being thrown in the line

For Each entry As DictionaryEntry In RReader

The exception reads as this

ResX file Type System.Windows.Forms.FlatStyle, System.Windows.Forms,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 in the data at 
line 121, position 4 cannot be located. Line 123, position 5. cannot be parsed.

Because of this, a .resx is not created and thus that form can't be translated.

I think the origin of the issue may be related to Infragistics, since I'm using Infragistics controls in the forms where the exception is being thrown and so far it looks like the ones whose .resx are being successfully duplicated do not use Infragistics.

Anyone has had a similar issue? Let me know if I haven't explained myself well enough.

Was it helpful?

Solution

Version=4.0.0.0

That's the problem. You are not running on .NET 4.0 (or later). So your program cannot load types from a version 4 assembly.

You exposed yourself to a Visual Studio bug that doesn't normally cause trouble. But does now that you start reading files that normally are only read when the program is being built. This problem got started when the original programmer created the project on VS2010 or later and picked the default .NET Framework version. Went about his business, designing the form as usual with the Localizable property set to True.

But then, later, changed the .NET Framework target version to 3.5 or less. Possibly to accommodate a customer that didn't want to install it. The VS bug is that this does not update the .resx file for the form. It still contains references to 4.0.0.0 types. It just never got around to it, the form was not opened in the designer. Not a problem on the dev's machine, he never noticed it, his build tools (like resgen.exe) have no trouble resolving version 4 types. But kaboom when your program tries to read it of course.

Assuming that you cannot target .NET 4, the only fix is to re-generate the .resx file. Open the form with the bad .resx file in the designer and make a trivial change to one of the properties. And just change it back. This recreates the .resx file, it will now use version 2.0.0.0 references. Double-check that the change was effective by looking at the .resx file with a text editor.

And you probably want to use Edit + Find and Replace + Find in Files to search all .resx files for "4.0.0.0" to make sure you have them all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top