[netcore] Allow reflection invocation of methods with ByRef return types (mono/mono...
authorFilip Navara <filip.navara@gmail.com>
Tue, 9 Apr 2019 08:42:18 +0000 (10:42 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 9 Apr 2019 08:42:18 +0000 (10:42 +0200)
commit5a786969f68a4bd42f6d5d39b2570110c197e6c6
tree5adc4242e69fa68b4d382adab353c05ca864a59e
parent768a9b68f77d89b4b2fbc0ebb3b1f8077143e866
[netcore] Allow reflection invocation of methods with ByRef return types (mono/mono#13901)

CoreCLR allows reflection on methods with ByRef return types under certain conditions. The PR implementing it is https://github.com/dotnet/coreclr/pull/17639.

Mono already implemented most of it in the marshalling code but artificially blocked it in `ves_icall_InternalInvoke`. I changed the condition for the exception to match the condition in `emit_invoke_call` (marshal-ilgen.c). It's similar to the condition in CoreCLR, but it may not handle byref-like types correctly. It would have to fixed on both places if it turns out to be the case.

The remaining issue is that null references returned in ByRef are not checked and converted to correct exception. It should result in `NullReferenceException` with special message that doesn't get wrapped in `TargetInvocationException`. I put a TODO marker at a place where I think it should be handled, but it's a bit over my head to implement it.

/cc @vargaz

Commit migrated from https://github.com/mono/mono/commit/444946325661fb1b76be77ae8398c3978eaf01c3
src/mono/mono/metadata/icall.c
src/mono/mono/metadata/marshal-ilgen.c