Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a strange problem with a resource file. I have on a WPF Window 2 buttons, their Content property is taken from a resx file. Those entries have the ConfirmationYes and ConfirmationCancel keys, and have been added only recently. I use an already defined StaticResource to get the Values from the resx file.

Here is my problem : when I tell the button to get its Content from the resx file, I get an error in the output saying that the key I specified is not to be found in that file, even though it is there, saved on the hard drive. If I use an older entry from the resource file, by replacing the ConfirmationYes or ConfirmationCancel with an older key, it finds the key and displays the correct text on the button.

I have no idea how to solve this, I hope some of you guys have run into this problem and can tip me on how to fix it.

Thanks in advance,
Updated 26-May-11 21:58pm
Tarun.K.S 27-May-11 4:28am    
Can you show the code you have written, it can help us to identify the problem quickly.
Marmotor 27-May-11 14:45pm    
I cannot do that, I signed a non disclosure agreement with my client. Sorry.

1 solution

You don't have to use *.RESX resources manually. This code is already generated for you.

Look at the auto-generated .CS file in a child node of your *.RESX node. Locate the auto-generated static class and its static string properties named after your string resources. Use them.

This way, you never need to use resource names. You would need to support string constants with the names, the compiler cannot check if they are valid or not. Why doing so if the .RESX file also has these names. It would be a violation of Do Not Repeat Yourself (DRY) principle, see't_repeat_yourself[^]. Auto-generates resource file makes your project maintainable.

Share this answer
Marmotor 27-May-11 14:44pm    
Thank you for your response. There was no auto-generated code file, the access modifier was set to Do not generate instead of Public. After changing that to Public, the code-behind file appeared and everything worked. Thank you again.

Sergey Alexandrovich Kryukov 27-May-11 14:52pm    
You're welcome, and thanks for accepting this answer.
Only I don't understand what's "there was no auto-generated code file". Every time you created a new *.RESX, the auto-generated code file is automatically created for you.

Good luck,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900