[Mono-dev] Mono fails to run binaries produced with .NET C# compiler.
Bitprox Development
devel at bitprox.com
Thu Apr 26 10:15:51 EDT 2007
Hi,
I am experiencing a problem when I try to run the code compiled using
the .NET Framework on the mono runtime. The same code runs fine when
executed on .NET
Framework. However when I compile the code using mono compiler mcs.exe
it runs fine on any
runtime. When I started to examine the IL code emitted by the csc.exe
and mcs.exe I noticed the difference that leads to unbounded recursion
and then a StackOverflowException.
To reproduce the problem the following steps required:
1. The library. Contains code:
using System;
namespace MainSpace
{
public interface IA
{}
public interface IB
{ bool Test(); }
public interface IC : IA, IB
{}
public interface ID : IC
{}
public class A : IA
{}
public class AC : A, IC
{
public virtual bool Test()
{
Console.WriteLine("AC.Test()"); return true;
}
}
public class CD : AC, ID
{}
}
2. The executable. Contains code:
using System;
namespace ImplSpace
{
internal class TestImpl : MainSpace.CD
{
public override bool Test()
{ Console.WriteLine("TestImpl.Test()"); return base.Test(); }
}
public class TestClass
{
public static void Main()
{
TestImpl ti = new TestImpl();
ti.Test();
}
}
}
3. The library and the executable now should be compiled using the
Microsoft csc.exe
C# compiler.
4. When executed using the .NET Framework the output is expected:
TestImpl.Test()
AC.Test()
5. When executed using the Mono-1.2.3/4 for Win32 the output is unexpected:
TestImpl.Test()
...
TestImpl.Test()
Unhandled Exception: System.StackOverflowException: The requested
operation caus
ed a stack overflow.
at ImplSpace.TestImpl.Test () [0x00000] ...
at ImplSpace.TestImpl.Test () [0x00000]
6. If the library and the executable are compiled using the Mono
compiler then no any
unexpected behaviour occurs.
The following IL code is generated using the csc.exe for the method
TestImpl.Test:
.method public hidebysig virtual instance bool
Test() cil managed
{
// Code size 21 (0x15)
.maxstack 1
.locals init ([0] bool CS$00000003$00000000)
IL_0000: ldstr "TestImpl.Test()"
IL_0005: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ldarg.0
IL_000b: call instance bool [FaultTestLib]MainSpace.CD::Test()
IL_0010: stloc.0
IL_0011: br.s IL_0013
IL_0013: ldloc.0
IL_0014: ret
} // end of method TestImpl::Test
The following IL code is generated using the mcs.exe for the method
TestImpl.Test:
.method public hidebysig virtual instance bool
Test() cil managed
{
// Code size 17 (0x11)
.maxstack 8
IL_0000: ldstr "TestImpl.Test()"
IL_0005: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ldarg.0
IL_000b: call instance bool [FaultTestLib]MainSpace.AC::Test()
IL_0010: ret
} // end of method TestImpl::Test
Now I can see that the the code produced by the csc.exe calls
MainSpace.CD::Test()
whereas code produced by the mcs.exe directly calls MainSpace.AC::Test().
Is there any possible solution for this kind of issue?
This is the first question of the Mono General FAQ: Q:" Can Mono run
binaries
produced by Visual Studio?", A: "Yes, Mono can run binaries produced by
Visual
Studio, there is no need to recompile."
My environment
OS: Windows
.NET: .NET Framework v1.1.4322
Mono: Mono-1.2.3/4 for Win32
Thanks,
Alex Makhotin
More information about the Mono-devel-list
mailing list