0

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 ..."

Elddif
  • 71
  • 1
  • 10

1 Answers1

0

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

binarytail
  • 16
  • 2
  • Hi, thank you for your response but this solution don't work either for me. :/ I have : calledType = {Name = "Resources" FullName = "TestNamespace.Resources"} and then an exception : "Method 'TestNamespace.Resources.PRG_CARTV' not found" But I will look link that you sent me. – Elddif Oct 12 '18 at 09:03
  • O, I found how to get this value with RessourceManager, thx! var myManager = new ResourceManager(typeof(ConsoleApp1.Properties.Ressources)); var myString = myManager.GetString("PRG_CARTV"); – Elddif Oct 12 '18 at 09:51