How do I retrieve resource string using C#?

Posted on 2005-04-18
Last Modified: 2012-05-05
I have a myresource.dll in which I have the text strings I need to retrieve.
What kind of declarations and code do I need to retrieve a string from this dll?
I believe I need to use the ResourceManager class and use its GetString method, but I don't know the COMPLETE code (including declarations, etc.) to make this work.

Let's say I have only one resource text string in this dll
Message = Hello.
Please give me the code to retrieve this text resource.

Question by:rj94070
    LVL 48

    Accepted Solution

    // Gets a reference to the same assembly that
    // contains the type that is creating the ResourceManager.
    System.Reflection.Assembly myAssembly;
    MyAssembly = this.GetType().Assembly;

    // Gets a reference to a different assembly.
    System.Reflection.Assembly myOtherAssembly;
    myOtherAssembly = System.Reflection.Assembly.Load("ResourceAssembly");

    // Creates the ResourceManager.
    System.Resources.ResourceManager myManager = new

    System.String myString;
    myString = myManager.GetString("StringResource");
    LVL 11

    Assisted Solution

    CheckOut this article which explains how to add resources and retrive them.
    LVL 23

    Assisted Solution

    It really depeds on how the data was stored.  If it's in a resource file, then you'd want to use the ResourceManager object.  If it's stored in a .net dll, then you may want to use reflections.  Finally, if your data is stored in a COM object (vb6.dll or C++.dll), you'll have to use the Runtime.Interop namespace in conjunction with the DllImport attribute.

    You mentioned that your data is stored in a DLL.  What kind of DLL is it (.Net assembly, or COM object)?

    public static string GetMyResourceString();

    public Button1_ClickEvent()
       TextBox1.Text = GetMyResourceString();

    Author Comment

    I don't know why I have to do
    // Gets a reference to a different assembly.
    I have only one resource assembly in my solution.

    I need the code for GetMyResourceString()

    To clarify: I created a .resx file then created a .NET dll. I put this dll in a separate "Output: Class Library" project within a solution. There is no code in this dll other than a .resx .


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now