我有一个非常简单的表单,我想要本地化(实际上我在这个项目中有很多表单,它们都有同样的问题)。当我将表单属性 Localizable
设置为 true 时,Visual Studio 会生成一个具有表单名称的 .resx
文件(如您所期望的)。但问题是它向 .resx 文件添加了其他任何东西都无法打开的各种内容(例如 WinRes、ResEx、Simple Resx Editor、RESX Editor 等)。
我得到的错误是:
ResX 文件类型 System.Drawing.Point、System.Drawing、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b03f5f7f11d50a3a 无法定位第 125 行、位置 4 处的数据。
第 127 行,位置 5。无法解析。
第 124 到 127 行是:
<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>
现在我假设 Visual Studio 添加了这个,以便我可以根据语言移动按钮等(我不需要或不想要这种能力)。但是,它会在除 Visual Studio 之外的每个编辑器中引发上述错误。
我安装的唯一扩展(根据扩展管理器)是:
- 突出显示所有出现的所选单词
- Microsoft Ribbon for WPF(我在本项目中没有使用)
加载项管理器显示没有加载项。
编辑:
在深入研究并手动编辑 .resx
文件后,问题实际上出在第 124 行 < assembly alias="System.Drawing" name=" System.Drawing,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
特别是 Version=4.0.0.0
。
如果我将其设置为 Version=2.0.0.0
,那么无论是在 Visual Studio 中还是在所有外部程序中,一切都正常。但问题是,如果我在 Visual Studio 中编辑任何内容,它会将其重置回 Version=4.0.0.0
。
目前,我将将目标框架设置为 .NET Framework 3.5 客户端配置文件,以便 Visual Studio 不会覆盖该版本。这是一种解决方法,意味着我无法使用 .NET 4.0 功能。
我的猜测是否正确,要么是 .NET Framework 中存在错误,要么是每个 .resx 编辑器(包括 Microsoft 的)中存在错误。
编辑2:
事实证明,当我尝试使用 Microsoft 的 WinRes.exe 工具时,我实际上启动了 .NET Framework 3.5 版本,因为 .NET Framework 4.0 版本没有安装。
我必须从 http 安装 .NET Framework 4.0 SDK ://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe 然后我就可以使用 WinRes.exe 4.0 编辑 .resx 文件
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
发布评论
评论(5)
Visual Studio 创建正确的 *.resx 文件。问题是,您尝试使用的工具是为规范的早期版本创建的。这就是您的解决方法有效的原因。
请检查您正在使用的本地化工具是否有新版本或补丁。
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.
有时,在特定情况下,Windows 窗体设计器在使用 *.resx 文件验证窗体期间会崩溃。
控制附加数据源的位置会受到此行为的影响。就我而言,我有一些数据集作为网格、组合的数据源...
所以我打开了设计器,但它没有告诉我它无法打开,因为名为:blabla 的控件出现问题,
在检查设计器文件后我什么也没发现控件有问题,只是 *.resx 文件指向错误的源,因为我重构了数据集。因此由于此次重构,*.resx 尚未更新。
我打开*.resx文件,简单地搜索了控件的标识符,发现了一段Base64编码的代码。 删除块内的值而不删除环绕标记将解决此控件的问题,因为 Windows 窗体设计器将自动刷新并将缺少的内容重新添加到 *.resx 文件中。
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.
在 .resx 中,找到 Base64 编码字符串的第一行。结尾应该是“j00LjAuMC4w”(意思是.net 4.0)。尝试将其更改为“j0yLjAuMC4w”(表示.net 2.0)。为我工作。感谢 Luis Mack http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-lated-to-beta2-bug-5252020#
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#
当编译器丢失某个对象的引用或者您更改了该对象的重要属性时,例如,如果您在表单所有设置中有一个网格(这意味着您正在使用 DataSet 作为数据),则会出现此错误源来完成你的网格),并且你改变了你的DataSet的名称VS失去了这个链接,他会给你带来这个消息。
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.
我刚刚删除了 .RESX 文件中的这些行
i just deleted thease lines in my .RESX file