Search code examples
c#embedded-resourceresourcemanager

Resource manager exception, no solution seems to work


Trying to use resource manager to get a string from a resource in a project, I keep getting the following exception:

An unhandled exception of type system.Resources.MissingManifestResourceException' occurred in mscorlib.dll.

So I decided to create a console app to test it and I am still getting the same problem, I have tried various solutions and always get the same exception.

Heres my code:

using System;
using System.Reflection;
using System.Resources;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ResourceManager rm = new ResourceManager("Resource1", Assembly.GetExecutingAssembly());
            string someString = rm.GetString("test");

            Console.ReadKey();
        }
    }
}

My Resources file My solution structure


Solution

  • You need to include the namespace for your resource, try

    ResourceManager rm = 
       new ResourceManager("ConsoleApplication1.Resource1", Assembly.GetExecutingAssembly());
    

    I prefer to use type information like this

     ResourceManager rm = new ResourceManager(typeof(ConsoleApplication1.Resource1));
    

    Here's a great write-up about using ResourceManager.