Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Method CallByName in Versioned.vb is incorrectly compiled into a recursion.
Source of the method:
Public Shared Function CallByName(ByVal Instance As Object, ByVal MethodName As String, ByVal UseCallType As CallType, ByVal ParamArray Arguments As Object()) As Object
Return Interaction.CallByName(Instance, MethodName, UseCallType, Arguments)
monodis output of the method:
// method line 215
.method public static
default object CallByName (object Instance, string MethodName, valuetype Microsoft.VisualBasic.CallType UseCallType, object Arguments) cil managed
.custom instance void class [mscorlib]System.ParamArrayAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x3aac
// Code size 17 (0x11)
.locals init (
IL_0005: call object class Microsoft.VisualBasic.CompilerServices.Versioned::CallByName(object, string, valuetype Microsoft.VisualBasic.CallType, object)
IL_000c: ldloc 0
} // end of method Versioned::CallByName
As you can see, it is compiled into self recursion rather than calling Interaction.CallByName. Inlining Interaction.CallByName into Versioned.CallByName works around this problem.
@Rolf could we workaround the compiler bug somehow (I guess we won't be making investments in vbnc anymore with Roslyn on the horizon)?
Since all recent packages of mono-basic suffer from this, it'd be neat if it could be workarounded for official Xamarin packages at least.
The oldest tag I could compile without downgrading mono was 4.0 and it had the same issue.
@Alexander, yeah, I won't be doing much work on the compiler.
It should be possible to work around this in function itself though (at the very least by c&p the code from Interaction.CallByName as Toni suggested)
Uh, well, this is a bit odd. I compiled Microsoft.VisualBasic.dll with vbc.exe available from Microsoft.Net.Compilers and I got the same result. Isn't that the Roslyn compiler?
Is there any off chance the code has something wonky going on and both compilers are correct?
Yeah, that's Roslyn so it should be correct :)
Reading https://github.com/mono/mono-basic/blob/8a804fd8f12f2e6a002173bbbc0974197530ec2f/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/Versioned.vb#L32-L35 makes me feel like this could indeed be the issue, but I know zero about how that code is supposed to work.
Yep, this is compiler magic:
It's replacing calls to Interaction.CallByName with Versioned.CallByName
A simple workaround would probably be to swap the implementations of these two methods.
Since Roslyn agrees with the magic, it's probably the right move.
@Toni do you want to send a pull request to the mono-basic repository?
There you go. Swapped the bodies keeping argument names. Tested this works in practice and checked monodis output for correct IL in both of the bodies.
I've merged the PR, thanks a lot!