[2019-06] [runtime] Make cross-appdomain wrappers throw NIE for methods with ref struct args #14867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If we have a ref struct and a method that takes it as an argument:
If we create an instance of M in another domain and try to call it:
Mono will need to create a wrapper that can invoke M.M1 in the other domain. The way the wrapper works in
mono_marshal_get_xappdomain_invoke
is by creating an array of all the arguments that need to be serialized (seemono_get_xdomain_marshal_type
) and then serializing the whole array (by calling out toSystem.Runtime.Remoting.RemotingServices.SerializeCallData
). In the example it would make a two element array and try to serializer
ando
into it. For valuetypes it normally does this by boxing the argument. However sinceR
is a ref-struct, boxing it is not allowed.This works on .NET Framework.
However for Mono we would need to serilize
R
without boxing it, which seems challenging with our current setup.So for now we generate a wrapper that just throws a NotImplementedException if it is ever called.
This fixes #14809 (in that marshalling a TextWriter across domains works again) but in an unsatisfactory way (because you can't call any of the
ReadOnlySpan<char>
overloads on the transparent proxy object).Also mark
MethodInfo
andMethodBase
with[Serializable]
again so that unit testing with NUnit.ApplicationDomain works again (they need to serialize method info for stack traces, I think)Backport of #14863.
/cc @lambdageek