Trying to learn how to emit IL code, and I have run into a problem
which is probably mind-numbingly simple, but I cannot figure out what
I am missing. Here is the relevant code:
public void ProduceAssembly(string outName, string outString, int
numTimes)
{
assemblyName.Name=outName;
assemblyName.Version=new Version("1.0.1.0");
AssemblyBuilder stringAssembly=
Thread.GetDomain().DefineDynamicAssembly(assemblyN ame,
AssemblyBuilderAccess.RunAndSave);
ModuleBuilder module;
module=stringAssembly.DefineDynamicModule("MainMod ule",outName+".exe",true);
MethodBuilder mainMethod=module.DefineGlobalMethod("Main",
MethodAttributes.Static|MethodAttributes.Public,ty peof(void),Type.EmptyTypes);
Type[] writeLineParams={typeof(string)};
MethodInfo
writeLineMethod=typeof(Console).GetMethod("WriteLi ne",writeLineParams);
ILGenerator constructorIL=mainMethod.GetILGenerator();
//define two local vars to do a simple loop, a counter and a
total
LocalBuilder lbLoopVar1=constructorIL.DeclareLocal
(typeof(int));
lbLoopVar1.SetLocalSymInfo("MaxLoop"); <--BOOM!
When it hits SetLocalSymInfo, it dies with a SystemNullReference
exception. I am not certain what I am trying to reference that is
null; the lbLoopVar1 object IS being instantiated properly .
Suggestions? Feel free to point and jeer at my obvious stupidity, just
let me know what blindingly simple thing I'm missing.
*----------------------------------------------------*
Evolution doesn't take prisoners:Lizard
"I've heard of this thing men call 'empathy', but I've never
once been afflicted with it, thanks the Gods." Bruno The Bandit
http://www.mrlizard.com