0

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

abdul
  • 1,562
  • 1
  • 17
  • 22
  • Reading [here](https://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.90).aspx), you should be able to access the resource via: `string someString = ConsoleApplication1.Resources.Resource1.test;` – Quantic Jan 09 '17 at 20:42
  • Had to make a small edit, for some reason the Resources part wouldn't appear. But thank you that solves my problem! Although I would love to know why the other solution wouldn't work for me –  Jan 09 '17 at 20:45

3 Answers3

1

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.

RamblinRose
  • 4,883
  • 2
  • 21
  • 33
0

You have to fully qualify the resource name:

ResourceManager manager = new ResourceManager("ConsoleApplication1.Resource1", Assembly.GetExecutingAssembly());
Sorin Buse
  • 46
  • 3
0

Answer provided by Quantic worked for me, thanks Quantic!

string someString = ConsoleApplication1.Resources.Resource1.test;