Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type.IsInterface returns different values between .NET and Mono for byref types #39068

Closed
rolfbjarne opened this issue Jul 10, 2020 · 5 comments

Comments

@rolfbjarne
Copy link
Member

Description

Test case:

interface I {}

Console.WriteLine (typeof (I).MakeByRefType ().IsInterface);

shows True with Mono and False with .NET (on macOS using .NET Core using MonoVM).

Complete test case: consoleapp-fbd84e3.zip

Download, unzip, and run make both:

 $ make both
Mono output:
    I& IsInterface: True
.NET output:
    I& IsInterface: False

Configuration

$ dotnet --version
5.0.100-preview.7.20317.11
  • What OS and version, and what distro if applicable?

macOS 10.15

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jul 10, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@jkotas jkotas changed the title Type.IsInterface returns different values between .NET and Mono for reference types Type.IsInterface returns different values between .NET and Mono for byref types Jul 10, 2020
@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Jul 13, 2020
@marek-safar marek-safar added this to the 6.0.0 milestone Jul 13, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 4, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 5, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 5, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 6, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 7, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 7, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 7, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 7, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 10, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 14, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 18, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 18, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 19, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 19, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 20, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 21, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 24, 2020
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 24, 2020
… doesn't work the same way for byref types.

Ref: dotnet/runtime#39068

Fixes this test:

    MonoTouchFixtures.ObjCRuntime.RegistrarTest
        [FAIL] RefOutTest_INSCoding : System.InvalidCastException : Unable to cast object of type 'Foundation.NSString' to type 'Foundation.INSCoding&'.
            at ObjCRuntime.Runtime.GetINativeObject(IntPtr ptr, Boolean owns, Type target_type, Type implementation)
            at ObjCRuntime.Runtime.GetINativeObject(IntPtr ptr, Boolean owns, Type target_type)
            at ObjCRuntime.Runtime.GetINativeObject_Dynamic(IntPtr ptr, Boolean owns, IntPtr type_ptr)
            at ObjCRuntime.Runtime.get_inative_object_dynamic(IntPtr obj, Boolean owns, IntPtr type, Int32& exception_gchandle)
            --- End of stack trace from previous location ---
            at MonoTouchFixtures.ObjCRuntime.RegistrarTest.RefOutTest_INSCoding() in /Users/rolf/work/maccore/squashed-onedotnet/xamarin-macios/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs:line 2908
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Aug 24, 2020
… doesn't work the same way for byref types. (#9466)

Ref: dotnet/runtime#39068

Fixes this test:

    MonoTouchFixtures.ObjCRuntime.RegistrarTest
        [FAIL] RefOutTest_INSCoding : System.InvalidCastException : Unable to cast object of type 'Foundation.NSString' to type 'Foundation.INSCoding&'.
            at ObjCRuntime.Runtime.GetINativeObject(IntPtr ptr, Boolean owns, Type target_type, Type implementation)
            at ObjCRuntime.Runtime.GetINativeObject(IntPtr ptr, Boolean owns, Type target_type)
            at ObjCRuntime.Runtime.GetINativeObject_Dynamic(IntPtr ptr, Boolean owns, IntPtr type_ptr)
            at ObjCRuntime.Runtime.get_inative_object_dynamic(IntPtr obj, Boolean owns, IntPtr type, Int32& exception_gchandle)
            --- End of stack trace from previous location ---
            at MonoTouchFixtures.ObjCRuntime.RegistrarTest.RefOutTest_INSCoding() in /Users/rolf/work/maccore/squashed-onedotnet/xamarin-macios/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs:line 2908
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
@marek-safar
Copy link
Contributor

@lambdageek could you investigate what broke?

@lambdageek
Copy link
Member

There's no bug in the netcore version of Mono. Its output matches CoreCLR (and also .NET Framework, FWIW).

The outlier is Mono 6.* from https://github.com/mono/mono which prints True while all the rest print False.

If we want to fix this in mono/mono, I'll move the bug there.

@lambdageek
Copy link
Member

The issue btw, is this code. Non-netcore Mono would need to do the byref check, too.

ves_icall_RuntimeTypeHandle_GetAttributes (MonoReflectionTypeHandle ref_type, MonoError *error)
{
MonoType *type = MONO_HANDLE_GETVAL (ref_type, type);
#ifdef ENABLE_NETCORE
if (type->byref || type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR)
return TYPE_ATTRIBUTE_NOT_PUBLIC;
#endif
MonoClass *klass = mono_class_from_mono_type_internal (type);
return mono_class_get_flags (klass);
}

@marek-safar
Copy link
Contributor

Closing as by-design

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants