My code:
System.Resources.ResourceManager resourceManager = GetResourceManager();
string str = resourceManager.GetString("delete", new CultureInfo(1033));
In current project compiled under .NET 2.0 everything works as excepted. Variable str contains resource string for LCID 1033 – Delete, this is ok.
We are now upgrading to .NET 4.0, recompiled project under target framework .NET 4.0.
Now compiled as .NET 4.0 assemblies, it throws exception System.ArgumentNullException with message Value cannot be null..Stack trace:
at System.Threading.Monitor.Enter(Object obj)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
Interesting here is stacktrace, where it points to internal framework method in ResourceManager.InternalGetResourceSet which causes to call Monitor.Enter with null object. But i call method GetString with not null parameters GetString(“delete”, new CultureInfo(1033)).
This bug seems to be similar to System.ArgumentNullException in System.Threading.Monitor.Enter. Maybe some bug in Monitor.Enter, or something else?
Update:
When i look in debugger at object resourceManager.ResourceSets.Items[2].Value.Table["delete"] then it contains string value “Delete”. property Items[2] here pointing to LCID 1033. This means that resource manager already contains localized string for resource key delete in language 1033. Does anybody knows where can be error?
I also think that you should declare and use your own dictionary for storage since ResourceSets is marked as Obsolete under .NET 4.0