Skip to content

Commit 322de5e

Browse files
authored
Fix some tests failing at EmitBaseMethodCall with BadImageFormatException (#2827)
1 parent c88d146 commit 322de5e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,34 @@ public void EmitMethodBody(MethodBuilder proxyMethod, MethodBuilder callbackMeth
9494

9595
private static void EmitBaseMethodCall(ILGenerator IL, MethodInfo method)
9696
{
97-
IL.Emit(OpCodes.Ldarg_0);
97+
if (method.IsAbstract)
98+
{
99+
if (!method.ReturnType.IsValueType)
100+
{
101+
IL.Emit(OpCodes.Ldnull);
102+
}
103+
else if (method.ReturnType != typeof(void))
104+
{
105+
var local = IL.DeclareLocal(method.ReturnType);
106+
IL.Emit(OpCodes.Ldloca, local);
107+
IL.Emit(OpCodes.Initobj, method.ReturnType);
108+
IL.Emit(OpCodes.Ldloc, local);
109+
}
110+
111+
IL.Emit(OpCodes.Ret);
112+
}
113+
else
114+
{
115+
IL.Emit(OpCodes.Ldarg_0);
98116

99-
for (int i = 0; i < method.GetParameters().Length; i++)
100-
IL.Emit(OpCodes.Ldarg_S, (sbyte) (i + 1));
117+
for (int i = 0; i < method.GetParameters().Length; i++)
118+
{
119+
IL.Emit(OpCodes.Ldarg_S, (sbyte) (i + 1));
120+
}
101121

102-
IL.Emit(OpCodes.Call, method);
103-
IL.Emit(OpCodes.Ret);
122+
IL.Emit(OpCodes.Call, method);
123+
IL.Emit(OpCodes.Ret);
124+
}
104125
}
105126

106127
private static void SaveRefArguments(ILGenerator IL, ParameterInfo[] parameters)

0 commit comments

Comments
 (0)