.NET Core 1.1 Resource File Issue
Asked Answered
J

6

20

In my .NET Core class library project, the resource file does not get updated when the resource file name contains a dot in it. For example, when I add Resources.en.resx or Resources.es.resx files in the .NET Core project, the custom tool is not able to generate or update the C# resource file. Here is error message:

Custom tool ResXFileCodeGenerator failed to produce an output for input file 'Resources.en.resx' but did not log a specific error.

If you know any workaround or any fix for it, please kindly point me to the right direction

Jacket answered 5/5, 2017 at 14:59 Comment(0)
G
15

Delete any .resx files currently in your Resources directory.

Now go to your Resources directory and right click for Add > New Item.

Choose Resource File and enter in a file name down the bottom of the form. It's important you get the name right first time and don't rename. You can use something like Resource.resx.

This very first Resource.resx file should have its own designer class. It also needs all the keys and values for localization for your project so if you have an existing Resource.en.resx you can copy and paste the values from that into this one.

If you need IStringLocalizer<Resource> or, in other words, you need to reference the Resource class somehow then you will need to go to Solution Explorer and left-click on the Resource.resx. In the Properties box there is a field called "Custom Tool". If you want a publically accessible class to be generated from the resx you will need to change this from ResXFileCodeGenerator to PublicResXFileCodeGenerator.

Now you can add the individual Resource.ja.resx, Resource.es.resx files. These do not need to have a custom tool ResXFileCodeGenerator run on them so you can remove that from the properties. This will fix your error message.

Goldagoldarina answered 25/9, 2017 at 19:35 Comment(3)
Now i have three files: (1) Resource.resx, (2) Resource.en.resx, and (3) Resource.es.resx. The Resource.resx file has all the keys vand values in English. Since it is default to English language, isn't it a duplication to create Resource.en.resx file? I understand that Resource.resx is for invariance culture.Jacket
Hi @Seth you can delete the Resource.en.resx if it is the default language. Just include the default stringsin the Resource.resxGoldagoldarina
Hi, could you mention some blog post or some repository to understand the best practices?Karole
S
46

Simply unload the project and reload it, the errors will disappear.

  1. Right click project in Solution Explorer > Unload Project
  2. Right click project in Solution Explorer > Reload Project
Snodgrass answered 5/12, 2020 at 19:7 Comment(3)
Yes! Sometimes it is just THAT simple!Oversexed
Amazing! This actually resolved my Resources files which are multiple languages. The Solution is simple Unload Your Resource Project and Reload It again In VS19 or Any Version.Stochmal
VS 2022 great, thanks!! Mano de SantoJolly
G
15

Delete any .resx files currently in your Resources directory.

Now go to your Resources directory and right click for Add > New Item.

Choose Resource File and enter in a file name down the bottom of the form. It's important you get the name right first time and don't rename. You can use something like Resource.resx.

This very first Resource.resx file should have its own designer class. It also needs all the keys and values for localization for your project so if you have an existing Resource.en.resx you can copy and paste the values from that into this one.

If you need IStringLocalizer<Resource> or, in other words, you need to reference the Resource class somehow then you will need to go to Solution Explorer and left-click on the Resource.resx. In the Properties box there is a field called "Custom Tool". If you want a publically accessible class to be generated from the resx you will need to change this from ResXFileCodeGenerator to PublicResXFileCodeGenerator.

Now you can add the individual Resource.ja.resx, Resource.es.resx files. These do not need to have a custom tool ResXFileCodeGenerator run on them so you can remove that from the properties. This will fix your error message.

Goldagoldarina answered 25/9, 2017 at 19:35 Comment(3)
Now i have three files: (1) Resource.resx, (2) Resource.en.resx, and (3) Resource.es.resx. The Resource.resx file has all the keys vand values in English. Since it is default to English language, isn't it a duplication to create Resource.en.resx file? I understand that Resource.resx is for invariance culture.Jacket
Hi @Seth you can delete the Resource.en.resx if it is the default language. Just include the default stringsin the Resource.resxGoldagoldarina
Hi, could you mention some blog post or some repository to understand the best practices?Karole
U
6

I'm using VS2019 with .Net Standard 2.0 and still this error remain. I've try and try, ... deleting file, clean, rebuild. But still the error remain.

I've ended up to using ResXManager witch work fantastically well, it is available from the Visual Studio marketplace.

https://marketplace.visualstudio.com/items?itemName=TomEnglert.ResXManager

Thumb up for the ResXManager team!

Unwarrantable answered 23/4, 2020 at 20:50 Comment(2)
Maybe it was the restart of Visual Studio (needed for installing ResXManager), but after the installation of ResXManager finally Visual Studio started recognizing Resources even in Intellisense and the annoying error disappeared magically. Great suggestion, @Unwarrantable ! And the tool looks great!Mousy
Just installing it fixed the issue for me as well ...Burchett
L
2

Based on the answer of @David Rawson I have been able to solve the error by doing the following:

  1. In the solution explorer Click on the Resource file that is mentioned in the error message
  2. Click F4 (for opening the Properties window)
  3. On Custom Tool on <reset to default>

That's it!

The error came up because I have changed the Access Modifier of the resource file from no code generation to public while I was testing some stuff.

Loper answered 23/3, 2021 at 10:57 Comment(1)
This is a good first point to look at. I had this error in VS2022, and it was because one of my resource files without code-behind had set a custom tool. Removing the custom tool simply removed this error.Yakka
C
0

After adding AsemblyInfo.tt into Properties folder, just save it ignore errors (but allow build), then close VS, and run it again. Works for VS2022 :)

Convenance answered 3/3, 2023 at 17:14 Comment(0)
V
0

This error consistently occurs for me while developing on a windows machine and has something to do with updating the resx file while using the windows GUI editor. While the answer above certainly works, the fastest and most consistent way I have been able to fix it (gratefully available to me because I am developing on mobile with two machines) is to push the edited resx to a remote branch, pull the code down on a mac, and make a minor edit to the resx file from the code view rather than the GUI view. Usualy I just add a space to the end of a string.

The auto generation of the Designer.cs file will kick in and regenerate the file. From there, undo your minor change to the resx, save, and the Designer will update again. Push that to your remote branch and the corrected/ errorless Designer.cs file will be available.

Vale answered 21/7, 2023 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.