problem running code in the article Late binding with Reflection by Sam Haider
the following is the code snippet and throws the exception:
"object reference not set to an instance of and object"
//--------code snippet---------
MethodInfo mi;
Object result = null;
object[] args = new object[]{"ABC123"};
try
{
Assembly assemblyInstance = Assembly.LoadFrom(@"C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\System.Data.dll");
Type[] types = assemblyInstance.GetTypes();
foreach (Type t in types)
{
mi = t.GetMethod("Constraint");
if (mi!=null)
{
string typeName = t.FullName;
object lateBoundObj = assemblyInstance.CreateInstance(typeName);
result = t.InvokeMember(typeName,BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, lateBoundObj, args);
break;
}
}
string name = result.ToString();
MessageBox.Show("Name is :",name);
}
catch(Exception ex)
{
MessageBox.Show("Error");
MessageBox.Show(ex.Message);
}
//-------------------------------------------