"AccessViolationException was Unhandled" Error in C # Managed Code

I have a new problem. My code is:

.method public static void  Main() cil managed
{
  .entrypoint
  // Code size       3 (0x3)
  .maxstack  1
  IL_0000:  ldnull
  IL_0001:  stloc.0
  IL_0002:  ret
} // end of method Program::Main

C # code:

il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);

I generate this code through the System.Reflection and System.Reflection.Emit classes. Does anyone know why this is not possible? Please, help.

My error

One small question - should I generate a constructor?

+5
source share
1 answer

You are trying to store zero in local 0 ( stloc.0), but in fact you have no specific locales.

DeclareLocal , Emit , LocalBuilder (, stloc, LocalBuilder); stloc.0, .

+7

All Articles