Resource (RESX) files messed up

怎甘沉沦 提交于 2019-12-04 04:02:07

I had the same problem - Designer.cs file not being present for some resx files.

The fix was to set the properties for the resx files:

Build Action - Embedded Resource
Custom Tool  - PublicResXFileCodeGenerator

This is what ASP.NET documentation says about resources files.

It does not talk specifically about codebehind designer files generated on the fly but if you read the bolded text carefully, it is essentially saying that you need the base file without language specified and, given that, it makes sense that only this file will include autogenerated code.

"When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language and culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:

•WebResources.resx

The base resource file. This is the default (fallback) resource file.

•WebResources.es.resx

A resource file for Spanish.

•WebResources.es-mx.resx

A resource file for Spanish (Mexico) specifically.

•WebResources.de.resx

A resource file for German."

I actually have never noticed this before but when I went to check my old projects, I saw they all have the base file and then language specific ones. So I just corrected it to follow that convention and it works now.

If I were you, I would:

create a new resx file; open the old one; Press ctrl+a in the old one; Press ctrl+v in the new one; Save the new one; Delete the old one; Rename the new one :)

This should solve the problem quiet fast. You could also check if the cs files are not excluded from the file by clicking the show all button

Sorry for using this to write a comment. My reputation actually is less than 50 =( but i think this might be important too.

This referes to Alvis' answer: Your solution did the trick. But i had also to modify the access modifier of properties in the base designer code file from internal to public. Otherwise i got XmlParseExceptions when trying to access the resx in xaml.

Edit: So this referes to C#/WPF. Could be different in ASP.NET

I found the best way was to:

  • Create the file as the default: Resource1.resx
  • Let it create the: Resource1.Desinger.cs
  • Rename it to what language you want, e.g., Localize.en.resx

Any other way for me just stopped creating the X.Designer.cs files

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