Permalink
Browse files

Avoid passing a Module to the GetSigHelper methods (), which can happ…

…en if an ILBuilder is used from a dynamic method. Fixes #1900.
  • Loading branch information...
1 parent 5427d4d commit b42fb3a0fa6a428a78e3d4ee88847d7afd870502 @vargaz vargaz committed Jan 20, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
@@ -839,7 +839,9 @@ public virtual void EmitCall (OpCode opcode, MethodInfo methodInfo, Type[] optio
public virtual void EmitCalli (OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
{
- SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module, 0, unmanagedCallConv, returnType, parameterTypes);
+ // GetMethodSigHelper expects a ModuleBuilder or null, and module might be
+ // a normal module when using dynamic methods.
+ SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module as ModuleBuilder, 0, unmanagedCallConv, returnType, parameterTypes);
Emit (opcode, helper);
}
@@ -848,7 +850,7 @@ public virtual void EmitCalli (OpCode opcode, CallingConventions callingConventi
if (optionalParameterTypes != null)
throw new NotImplementedException ();
- SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module, callingConvention, 0, returnType, parameterTypes);
+ SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module as ModuleBuilder, callingConvention, 0, returnType, parameterTypes);
Emit (opcode, helper);
}
@@ -950,7 +952,7 @@ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
if (locals != null) {
foreach (LocalBuilder local in locals) {
if (local.Name != null && local.Name.Length > 0) {
- SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module);
+ SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module as ModuleBuilder);
sighelper.AddArgument (local.LocalType);
byte[] signature = sighelper.GetSignature ();
symbolWriter.DefineLocalVariable (local.Name, FieldAttributes.Public, signature, SymAddressKind.ILOffset, local.position, 0, 0, local.StartOffset, local.EndOffset);

0 comments on commit b42fb3a

Please sign in to comment.