T
Tony Johansson
Hi!
This program is supposed to create these rows dynamically
Hashtable tbl new Hashtable();
tbl.Add("Hi","Hello");
int foo = tbl.Count;
Here I have a simple example that give exception when this row is being
executed
*ConstructorInfo ctor = hashType.GetConstructor(argumentTypes);*
the exception I get is the following when I translated from my native
language
"NullReferenceException was unhandled
the Objectreference has not been given to an instance of an object"
Is it anyone that might have an idea what I have to change ?
static void Main(string[] args)
{
string path =
@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll";
Assembly theAssembly = Assembly.LoadFile(path);
Type hashType = theAssembly.GetType("Hashtable");
Type[] argumentTypes = Type.EmptyTypes;
ConstructorInfo ctor = hashType.GetConstructor(argumentTypes);
object newHash = ctor.Invoke(new object[]{});
MethodInfo method = hashType.GetMethod("Add");
method.Invoke(newHash, new object[] { "Hi", "Hello" });
PropertyInfo property = hashType.GetProperty("Count");
int count = (int)property.GetValue(newHash, null);
}
//Tony
This program is supposed to create these rows dynamically
Hashtable tbl new Hashtable();
tbl.Add("Hi","Hello");
int foo = tbl.Count;
Here I have a simple example that give exception when this row is being
executed
*ConstructorInfo ctor = hashType.GetConstructor(argumentTypes);*
the exception I get is the following when I translated from my native
language
"NullReferenceException was unhandled
the Objectreference has not been given to an instance of an object"
Is it anyone that might have an idea what I have to change ?
static void Main(string[] args)
{
string path =
@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll";
Assembly theAssembly = Assembly.LoadFile(path);
Type hashType = theAssembly.GetType("Hashtable");
Type[] argumentTypes = Type.EmptyTypes;
ConstructorInfo ctor = hashType.GetConstructor(argumentTypes);
object newHash = ctor.Invoke(new object[]{});
MethodInfo method = hashType.GetMethod("Add");
method.Invoke(newHash, new object[] { "Hi", "Hello" });
PropertyInfo property = hashType.GetProperty("Count");
int count = (int)property.GetValue(newHash, null);
}
//Tony