I just hit this same exception in a WPF project. The issue occurred within an assembly that we recently moved to another namespace (ProblemAssembly.Support
to ProblemAssembly.Controls
). The exception was happening when trying to access resources from a second resource file that exists in the assembly.
Turns out the additional resource file did not properly move references from the old namespace name to the new namespace name.
In the designer.cs for the resource file, there is a static property to get the ResourceManager. Within that getter, the string was still referring the old namespace. Once correcting it to the new namespace, the problem was resolved:
global::System.Resources.ResourceManager temp =
new global::System.Resources.ResourceManager(
"ProblemAssembly.Support.Properties.Stuff", typeof(Stuff).Assembly);
should have been:
global::System.Resources.ResourceManager temp =
new global::System.Resources.ResourceManager(
"ProblemAssembly.Controls.Properties.Stuff", typeof(Stuff).Assembly);
Hope this helps the next person.
I solved the problem like this:
It works perfectly.
When I tried sharing a resource.resx file from one C# project with another C# project, I got this problem. The suggestion on moving the Form class to the beginning of its file wasn't appropriate. This is how I solved it. You essentially use a link from the second project to the first, then enable regeneration of the resource.designer.cs
file.
Properties/Resources.resx
fileProperties/Resources.resx
file as a LINK to the Properties folder in the second project. Don't add it to the root level of the project.Properties/Resources.designer.cs
!Resources.resx
, add ResXFileCodeGenerator
as the CustomToolResources.resx
and select "Run Custom Tool". This will generate a new designer.cs file.Note: I would avoid editing the resource.designer.cs file, as this is autogenerated.
In my case a series of badly thought global text replacements had inadvertently changed this line in the resource designer cs file.
Since the namespace in that argument did not match the namespace of the class anymore, the application got confused at run time.
Check that the namespace of the designer matches the string argument in that line.
It happens because the *.resх
is excluded from migration.
I found that deleting the designer.cs file, excluding the resx file from the project and then re-including it often fixed this kind of issue, following a namespace refactoring (as per CFinck's answer)
No-one seems to have mentioned this solution. Obvious really - but tripped me over for a moment...
The default access modifier for a new resources file is Internal
(or Friend
in VB.Net.)
Make sure you change this to Public
(in the resx designer there is a dropdown at the top for the access modifier)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With