C# resx file error

隐身守侯 提交于 2019-11-27 07:50:20

问题


I'm getting a weird error with my .resx files:

"Invalid Resx file. ResX input is not valid. Cannot find valid "resheader" tags for the ResX reader and writer type names. C:\Documents and Settings\Users\My Documents\Visual Studio 2010\Projects\dock\WinForms\Dock\strings.resx"

What I did was replace some files in an existing VS 2010 solution with some older ones from VS 2008 solution, most of the files work fine but I get this error and I don't know how to fix it. If it makes a difference, here is the source code of that file.

I'm using NET WinForms 4.0, if that matters.


回答1:


  <resheader name="resmimetype">
    <value>
      text/microsoft-resx
    </value>
  </resheader>

Extra white space got added somehow. You'll need to remove it so it looks like this:

  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>

You also must update the version numbers in the assembly references from 2.0.0.0 to 4.0.0.0. Copying .resx files like this is otherwise a good way to get into trouble. You'll easily get the White Screen of Darn when the designer generated code tries to use a missing value in the .resx file.




回答2:


Alright so what I did in order to solve your problem was add these lines to your file just before /root:

  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>1.3</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>

I created a new VS2010 solution, added a new .resx file the usual way and looked at the structure of the generated file. I found these lines which, apparently, VS needs in order to compile your file appropriately.

Hope I helped :)

EDIT:

Oops my bad, I didn't notice the existing tags in your file. Anyway, it still solves your problem and you can just delete the old tags and keep these instead.




回答3:


In my case, I had downloaded the control from somewhere. All of the source files were in a folder, and the resx file was in the App_LocalResources subfolder. I didn't actually care about anything in the resx file part of it, I think it ws mostly auto-generated blank tags. So I just deleted the resx file. After deleting the resx file, the control compiled successfully.



来源:https://stackoverflow.com/questions/8390447/c-sharp-resx-file-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!