I try to get a value of ressource.resx and I can't.
I do :
foreach (string certif in ContactCertifications)
{
Type calledType = Type.GetType("TestNamespace.Resources");
String s = (String)calledType.InvokeMember(certif,BindingFlags.InvokeMethod
| BindingFlags.Public |BindingFlags.Static,null,null,null); }
certif = "PRG_CARTV"
calledType is : {Name = "Resources" FullName = "TestNamespace.Resources"} and when I'm in line "String s = (String)calledType" I have an error : "Method 'TestNamespace.Resources.PRG_CARTV' not found."
And when I have String s = TestNamespace.Resources.PRG_CARTV;
it's work, so I don't understend..
When I do simply :
var myManager = new ResourceManager(typeof(Resources));
var myString = myManager.GetString("PRG_CARTV");
it's doesn't work, I have a error : "Can not find appropriate resources for the specified culture or neutral culture. Make sure \\ "TestNamespace.Ressources.resources \\" has been correctly embedded or linked in the assembly ..."
You have 2 problems here:
1) Getting the value of a resource via reflection, I tried this one and worked:
String s = (String) calledType.InvokeMember(certif, BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Static, null, null, null);
Note the binding flags that changed: BindingFlags.GetProperty
instead of BindingFlags.InvokeMethod
and BindingFlags.NonPublic
instead of BindingFlags.Public
2) Issue with the ResourceManager. I myself would try to recreate the Resources.resx again. If you want to investigate further check similar problems here in StackOverflow, for example: Could not find any resources appropriate for the specified culture or the neutral culture
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.