Need help defining the .NET Resource Fallback

Posted on 2007-10-01
Last Modified: 2013-12-17
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");

Question by:theperfectstorm
    LVL 9

    Accepted 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.

    Author Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now