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

GetFunctionPointerForDelegateTests tests fail with Specified cast is not valid on Browser #39187

Open
mdh1418 opened this issue Jul 13, 2020 · 14 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-Interpreter-mono disabled-test The test is disabled in source code against the issue
Milestone

Comments

@mdh1418
Copy link
Member

mdh1418 commented Jul 13, 2020

When running System.Runtime.InteropServices library tests on Browser wasm, two functions fail with Specified cast is not valid:

  • GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsExpected
  • GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected

Note

When the tests are not ordered, the suite sometimes fails with the two tests above

[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsExpected
System.InvalidCastException : Specified cast is not valid.
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected
System.InvalidCastException : Specified cast is not valid.
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

And other times, it fails with the six tests from GetDelegateForFunctionPointerTests.cs

[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate))
Assert.IsType() Failure
Expected: System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate
Actual: System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests+NonGenericDelegate
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.MulticastDelegate))
Assert.IsType() Failure
Expected: System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate
Actual: System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests+NonGenericDelegate
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+OtherNonGenericDelegate))
Assert.IsType() Failure
Expected: System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate
Actual: System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests+NonGenericDelegate
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_GenericInvalidType_ReturnsExpected
Assert.IsType() Failure
Expected: System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate
Actual: System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests+NonGenericDelegate
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_CollectibleType_ReturnsExpected
Assert.IsType() Failure
Expected: System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate
Actual: System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests+NonGenericDelegate
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_Generic_ReturnsExpected
System.InvalidCastException : Specified cast is not valid.
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
@ghost
Copy link

ghost commented Jul 14, 2020

Tagging subscribers to this area: @BrzVlad, @lewurm
Notify danmosemsft if you want to be subscribed.

@vargaz
Copy link
Contributor

vargaz commented Jul 31, 2020

These now fail with:
System.PlatformNotSupportedException : No native to managed transitions on this platform.
They cannot be supported without the pinvoke generator.

@lewing
Copy link
Member

lewing commented Aug 1, 2020

@vargaz this sounds like net6?

@vargaz
Copy link
Contributor

vargaz commented Aug 1, 2020

Probably.

@pavelsavara
Copy link
Member

pavelsavara commented Jun 16, 2021

I will remove the [ActiveIssue] from System.Net.Http.Functional.Tests in my PR #54289 because it works there.

@pavelsavara
Copy link
Member

This was probably fixed already. The remaining [ActiveIssue] are in src\libraries\System.Runtime.InteropServices\tests\System\Runtime\InteropServices\Marshal\GetFunctionPointerForDelegateTests.cs but that is in assembly which is not targeting Browser right now.

@mdh1418 how did you made them run on browser before ?

@vargaz
Copy link
Contributor

vargaz commented Aug 5, 2021

This PR:
#56883
will fix the error handling, so it will now fail with a more reasonable error message.

@SamMonoRT
Copy link
Member

@lewing - is this a must for 6.0 ?

@SamMonoRT SamMonoRT added the disabled-test The test is disabled in source code against the issue label Aug 12, 2021
@SamMonoRT
Copy link
Member

Moving to 7.0

@SamMonoRT SamMonoRT removed this from the 6.0.0 milestone Aug 12, 2021
@SamMonoRT SamMonoRT added this to the 7.0.0 milestone Aug 12, 2021
@ilonatommy
Copy link
Member

@vargaz, are we able to solve it in 7.0?

@radical radical modified the milestones: 7.0.0, 8.0.0 Aug 12, 2022
@lewing
Copy link
Member

lewing commented Jul 11, 2023

@ilonatommy can you check if these tests still fail?

@ilonatommy
Copy link
Member

ilonatommy commented Jul 11, 2023

The error message changed to:

[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_CantCast_ThrowsInvalidCastException
   System.PlatformNotSupportedException : No native to managed transition for method 'void System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests:Method (string)', missing [UnmanagedCallersOnly] attribute.
  at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(Delegate d)
  at System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_CantCast_ThrowsInvalidCastException()
  at System.Reflection.MethodInvoker.InterpretedInvoke(Object obj, IntPtr* args)
  at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

When we use the hint and add the decorator:

        [UnmanagedCallersOnly]
        private static void Method(string s) { }

GetFunctionPointerForDelegateTests.cs(124,36): error CS8894: Cannot use 'string' as a parameter type on a method attributed with 'UnmanagedCallersOnly'

When we change the method to receive char* in unsafe context, the message is back to missing [UnmanagedCallersOnly], so apparently I am not using it correctly.

I am not sure how to fix this.

Tests failing with this message:

[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_CantCast_ThrowsInvalidCastException
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_GenericInvalidType_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+NonGenericDelegate))
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.MulticastDelegate))
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(t: typeof(System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests+OtherNonGenericDelegate))
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_Generic_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetDelegateForFunctionPointerTests.GetDelegateForFunctionPointer_CollectibleType_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsExpected
[FAIL] System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointerForDelegate_NormalDelegateNonGeneric_ReturnsExpected

@lewing
Copy link
Member

lewing commented Jul 21, 2023

@vargaz is this something we expect to work?

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 21, 2023
vargaz added a commit to vargaz/runtime that referenced this issue Jul 21, 2023
@lewing lewing modified the milestones: 8.0.0, 9.0.0 Aug 13, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 26, 2024
@lewing
Copy link
Member

lewing commented Feb 21, 2024

cc @kg @BrzVlad

@lewing lewing modified the milestones: 9.0.0, Future Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Codegen-Interpreter-mono disabled-test The test is disabled in source code against the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants