Visual Studio creates invalid Resx files
Asked Answered
G

5

15

I have a pretty simple form that I am wanting to localize (I actually have quite a few in this project, they all have the same problem). When I set the form property Localizable to true Visual Studio generates a .resx file with the form name (as you would expect). The problem though is that it's adding all sorts of things to the .resx file that nothing else can open (eg WinRes, ResEx, Simple Resx Editor, RESX Editor etc).

The error I get is:

ResX file Type System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a the data at line 125, position 4 cannot be located. Line 127, position 5. cannot be parsed.

Line 124 to 127 is:

<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="lblUsername.Location" type="System.Drawing.Point, System.Drawing">
  <value>26, 24</value>
</data>

Now I'm assuming that Visual Studio is adding this so that I can move buttons etc around depending on the language (I don't need or want this ability). However, it throws the above error in every editor other than Visual Studio.

The only extensions that I have installed (according to the Extension Manager) are:

  • Highlight all occurrences of selected word
  • Microsoft Ribbon for WPF (which I'm not using in this project)

Add-in manager shows no Add-ins.

Edit:

After digging around and manually editing the .resx file, the problem is actually with line 124 <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> specifically with Version=4.0.0.0.

If I set this to Version=2.0.0.0 then everything works, both in Visual Studio, and in all the external programs. The problem with this though is that if I edit anything within Visual Studio it will reset it back to Version=4.0.0.0.

For the time being I am going to set the Target Framework to .NET Framework 3.5 Client Profile so that Visual Studio doesn't override the version. This is a workaround and means that I can't use .NET 4.0 features.

Am I right in guessing that there's either a bug in the .NET Framework, or every single .resx editor out there (including Microsoft's).

Edit 2: It turned out that when I was trying to use Microsoft's WinRes.exe tool I was actually launching the .NET Framework 3.5 version, since the .NET Framework 4.0 version doesn't get installed.

I had to install the .NET Framework 4.0 SDK from http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe and I was then able to edit the .resx files with WinRes.exe 4.0

Genitourinary answered 9/11, 2010 at 9:58 Comment(9)
Did you do 'PublicKeyToken=REMOVED' OR is that the exact error message? Also Drawing is spelt wrong there.Madancy
That's me typing it. I'll edit it and add it back in. No harm in a public key being there I guess.Genitourinary
@Blair McMillan: Not yours anyways :)Madancy
@Blair McMillan: I suspect that , between the 2 numbers is causing the issue with certain cultures.Madancy
@leppie: I don't understand why VS generates invalid code though. I don't even want that option there, I only want the text strings anyway.Genitourinary
Updated my question with a workaround. Still doesn't explain why VS makes invalid files.Genitourinary
@Blair: You say that Visual Studio works but every other editor doesn't. How is that a VS bug? Surely it's a bug with every other editor.Convertite
@Jeff: Yes. Including the tool make by Microsoft (WinRes) that comes with Visual Studio SDK. It apparently hasn't been updated since .NET 3.5Genitourinary
My bad. It has been updated, it just isn't installed.Genitourinary
K
6

Visual Studio creates correct *.resx files. The problem is, tools that you are attempting to use were created for previous version of the specification. That's why your workaround works.

Please check if there are no newer versions or patches to localization tools you are using.

Krystinakrystle answered 9/11, 2010 at 13:43 Comment(3)
True. I can't find the 4.0 version of WinRes.exe though (Microsoft's tool that is meant to come with VS).Genitourinary
WinRes.exe 4.0 is installed with .NET Framework SDK which can be downloaded from download.microsoft.com/download/A/6/A/…Genitourinary
@Paweł Dyda: Well, it creates correct *.resx files, but it reads them incorrectly. For example, it saves <value>Ctrl+O</value>, but if the OS is German, it can only read the key if the value is "<value>Strg+O</value>". And I consider the resulting fact, that a correct source code can only be compiled on an english operating system as an a bit questionable approach ...Gelatinoid
F
5

Sometimes in specific cases the windows forms designer crashes during validating the form with the *.resx files.

Controls where a DataSource was attached are affected from this behavior. In my case I got some DataSets as DataSource for Grids, Combos...

So I have opened the Designer and it't telling me it cannot open due a problem with a control named: blabla

after checking the designer-file I found out nothing is wrong with the control it's just the *.resx file pointing to a wrong source, because I refactored the DataSet. So the *.resx has not updated due this refactoring.

I opened the *.resx file and simply searched for the identifier of the control and found a Base64 encoded code. Deleting the value inside the block without deleting the surround tags will resolve the problem for this control as the windows forms designer will automatically refresh and readd the missing content to the *.resx file.

Fieldstone answered 13/11, 2013 at 7:55 Comment(0)
G
3

In the .resx, locate the first line of the base64 encoded string. The end should be "j00LjAuMC4w" (meaning .net 4.0). Try changing that to "j0yLjAuMC4w" (meaning .net 2.0). Worked for me. Thanks to Luis Mack at http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020#

Guanidine answered 27/2, 2011 at 16:45 Comment(1)
This isn't the actual change I made, but it made me realize the problem was a library with the wrong version.Lawford
G
0

This error is presented when the compiler lost the reference of some object or when the you have changed a important property of this object, for example if you have a Grid on the form all setup (this means that you are using a DataSet as your data source to fulfill your grid), and you change the name of your DataSet VS lost this link, he will bring you this message.

Giustino answered 19/2, 2015 at 15:56 Comment(0)
B
0

i just deleted thease lines in my .RESX file

<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken="" />
Buzzer answered 2/12, 2018 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.