I have been able to successfully execute other methods using reflection but I am now getting a TargetInvocationException. Although the TargetInvoationException points me to the methodInfo.Invoke method, stepping through the code shows the exception occuring in the Load method when SampleXMLToDataTable is called. The SampleXMLToDataTable is a public static method in the same class as Load. The error is thrown as the code is attempting to enter the SampleXMLToDataTable.
Is there a problem calling methods from within other methods that are being called using reflection?
The code that calls via reflection:
private Object CreateXMLDataLoaderInstance(string xml)
{
object o = null;
Assembly demandAssembly = LoadSampleDemandAssembly();
Type assemblyType = demandAssembly.GetType("SampleDemand.XMLDataLoader");
MethodInfo methodInfo = assemblyType.GetMethod("Load");
o = Activator.CreateInstance(assemblyType, new Object[1] { true });
Object[] oParamArray2 = new Object[1];
methodInfo.Invoke(o, new Object[1] { xml });//TargetInvocationException
return o;
}
And the method it is trying to invoke:
public void Load(string xml)
{
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml);
XmlNode settingsNode = null;
foreach (XmlNode xNode in xDoc.FirstChild.ChildNodes)
{
string name = xNode.Name;
string wsx = xNode.ChildNodes[0].OuterXml;
XmlDocument doc = new XmlDocument();
doc.LoadXml(wsx);
DataTable dt = SampleXMLToDataTable(doc);//Where the code breaks
XMLSample xmlWS = new XMLSample(dt, wsx, name);
this.sample.Add(name, xmlWS);
}
if (settingsNode != null)
{
settings = GetSettings(settingsNode);
}
}