I have a self-hosted web api console app. It includes a linked resource image that I can access as:
Bitmap imgBitmap = Properties.Resources.img2
However I want to access it as variable. I.e. the name of the resource will be provided as a variable containing the string: "img2"
There are other questions on this issue, but they dont seem to work or have enough information for me to figure out how to do it. E.g.:
So I tried:
object obj = ResourceManager.GetObject("img2", Properties.Resources.resourceCulture);
But that gave me the error:
An object reference is required for the non-static field, method, or property 'System.Resources.ResourceManager.GetObject(string, System.Globalization.CultureInfo)' ...
So I tried to instantiate it (but I am unsure how exactly how to specify this) (I have tried various combinations) ...
var TheResourceManager =
new System.Resources.ResourceManager(
"Properties.Resources",
typeof(Properties.Resources).Assembly);
Bitmap imgBitmap = (Bitmap)TheResourceManager.GetObject("img2");
And that gave me the run time error...
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Properties.Resources.resources" was correctly embedded or linked into assembly "OwinWebApi2" at compile time, or that all the satellite assemblies required are loadable and fully signed."