visual-studio Visual Studio 创建无效的 Resx 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4132399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio creates invalid Resx files
提问by Blair McMillan
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 Localizableto true Visual Studio generates a .resxfile 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).
我有一个非常简单的表单,我想对其进行本地化(我实际上在这个项目中有很多表单,它们都有相同的问题)。当我将表单属性设置Localizable为 true 时,Visual Studio 会生成一个.resx带有表单名称的文件(如您所料)。但问题是它向 .resx 文件添加了其他任何东西都无法打开的东西(例如 WinRes、ResEx、Simple Resx Editor、RESX Editor 等)。
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.
ResX 文件类型 System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 第 125 行的数据,位置 4 无法定位。第 127 行,位置 5。无法解析。
Line 124 to 127 is:
第 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>
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 otherthan Visual Studio.
现在我假设 Visual Studio 正在添加它,以便我可以根据语言移动按钮等(我不需要或不想要这种能力)。然而,它抛出在每一个编辑器上面的错误其他比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)
- 突出显示所选单词的所有出现
- Microsoft Ribbon for WPF(我没有在这个项目中使用)
Add-in manager shows no Add-ins.
插件管理器不显示插件。
Edit:
编辑:
After digging around and manually editing the .resxfile, 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.
在挖掘并手动编辑.resx文件后,问题实际上出在第 124 行,<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />特别是Version=4.0.0.0.
If I set this to Version=2.0.0.0then 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.
如果我将它设置为Version=2.0.0.0那么一切正常,无论是在 Visual Studio 中,还是在所有外部程序中。但问题在于,如果我在 Visual Studio 中编辑任何内容,它会将其重置回Version=4.0.0.0.
For the time being I am going to set the Target Framework to .NET Framework 3.5 Client Profileso that Visual Studio doesn't override the version. This is a workaround and means that I can't use .NET 4.0 features.
目前,我将目标框架设置为 .NET Framework 3.5 Client Profile,以便 Visual Studio 不会覆盖该版本。这是一种解决方法,意味着我无法使用 .NET 4.0 功能。
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).
我是否正确地猜测 .NET Framework 中存在错误,或者那里的每个 .resx 编辑器(包括 Microsoft 的)。
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.
编辑 2:事实证明,当我尝试使用 Microsoft 的 WinRes.exe 工具时,我实际上是在启动 .NET Framework 3.5 版本,因为没有安装 .NET Framework 4.0 版本。
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.exeand I was then able to edit the .resx files with WinRes.exe 4.0
我必须从http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe安装 .NET Framework 4.0 SDK,然后我就可以编辑带有 WinRes.exe 4.0 的 .resx 文件
采纳答案by Pawe? Dyda
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.
Visual Studio 创建正确的 *.resx 文件。问题是,您尝试使用的工具是为规范的先前版本创建的。这就是您的解决方法有效的原因。
Please check if there are no newer versions or patches to localization tools you are using.
请检查您使用的本地化工具是否没有更新的版本或补丁。
回答by Spektakulatius
Sometimes in specific cases the windows forms designer crashes during validating the form with the *.resx files.
有时在特定情况下,Windows 窗体设计器在使用 *.resx 文件验证窗体时会崩溃。
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
所以我打开了设计器,但它没有告诉我由于名为 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 refactoredthe DataSet. So the *.resx has not updated due this refactoring.
检查设计器文件后,我发现控件没有任何问题,只是 *.resx 文件指向错误的源,因为我重构了数据集。所以*.resx 没有因为这个重构而更新。
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 tagswill 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 编码的代码。删除块内的值而不删除环绕标记将解决此控件的问题,因为 windows 窗体设计器将自动刷新并将丢失的内容读取到 *.resx 文件。
回答by servermanfail
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#
在 .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-related-to-beta2-bug-5252020#
回答by Caio Pimentel
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.
当编译器丢失某个对象的引用或您更改了该对象的重要属性时,会出现此错误,例如,如果您在窗体上有一个 Grid 所有设置(这意味着您正在使用 DataSet 作为您的数据source 来完成你的网格),而你更改了你的 DataSet 的名称 VS 失去了这个链接,他会给你带来这个消息。
回答by RAINA
i just deleted thease lines in my .RESX file
我刚刚删除了我的 .RESX 文件中的这些行
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken="" />

