C# resx file error

2019-01-20 11:59发布

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.

3条回答
成全新的幸福
2楼-- · 2019-01-20 12:40

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.

查看更多
Viruses.
3楼-- · 2019-01-20 12:43

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.

查看更多
叼着烟拽天下
4楼-- · 2019-01-20 12:55
  <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.

查看更多
登录 后发表回答