I'm trying get a resource for translation in ASP.NET, using conversion of string to type ResourceManager and a extertnal Resources file for translation. But when i execute i'm look this error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 24: Type myProp = element.GetProperty("ResourceManager").GetType();
Line 25: MethodInfo getString = myProp.GetMethod("GetString");
Line 26: var r = getString.Invoke(this, new object[] { key });
Line 27: return r.ToString();
Line 28: }
This is my code:
protected string getText(string key)
{
Type element = Type.GetType($"Website.Language.{translation}.general");
Type myProp = element.GetProperty("ResourceManager").GetType();
MethodInfo getString = myProp.GetMethod("GetString");
var r = getString.Invoke(this, new object[] { key });
return r.ToString();
}
Apparently, the getString
variable returns null, but te method "GetString" should be call "GetString" method of ResourceManager. Someone could help me with this?
Aucun commentaire:
Enregistrer un commentaire