[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

Need help defining the .NET Resource Fallback

I have the following code which tests if the resource is available, but it would be better if I didn't have to test the resource every time.  I would like the fall back resource to kick in automatically as it does when the resource files all have the same base name. In my case, the satellite assemblies and fall back resource files all have different base names.

ResourceManager resmgr;
Assembly a = Assembly.GetExecutingAssembly();
   resmgr = new ResourceManager("MyApp.Skins.CustomerB", a);
   string msg = resmgr.GetString("ClickHere");
catch (Exception ex)
   resmgr = new ResourceManager("MyApp.Properties.Resources", a);
   string msg = resmgr.GetString("ClickHere");

1 Solution
I don't think there is an automatic way that this can be done because people want to do things differently. However, have you considered building your own resource manager that inherits from ResourceManager. I have done that before and in my overridden GetString, I check to see if the resource is available and return a different string and show a message box if it doesn't.
theperfectstormAuthor Commented:
I have started implementing your solution. The built in resource manager does have a fall back mechanism which I can get to work, but all resource files have to have the same base name and only differ by the culture. But I can build in intelligence into the derived resource manager like adding a GetImage function which can do some of the up front work to display the image (avoid duplicate code).


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now