Skip to content

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Sep 9, 2025

Context: https://github.com/jonathanpeppers/IntuneReproNet9
Context: 35f41dc
Context: 9a27140

.NET 9 introduced a Java "instanceof" check for multiple reasons:

if (!JniEnvironment.Types.IsAssignableFrom (handleClass, typeClass)) {
    return null;
}

The problem with this check, is that it fails in combination with the package:

<PackageReference Include="Microsoft.Intune.Maui.Essentials.android" Version="11.0.0-develop" />

LayoutInflater.From (Context) returns null due to:

Handle 0x7f346ad02d is of type 'com/android/internal/policy/PhoneLayoutInflater' which is not assignable to 'com/microsoft/intune/mam/client/view/MAMLayoutInflater'

To solve this:

  • Introduce -p:_AndroidIsAssignableFromCheck=false to disable the check, defaulting to true for .NET 9+.

  • Add a test that calls LayoutInflater.From (Context) and verify it returns non-null.

  • Add a test entry in Remaps.xml to remap com.microsoft.intune.mam.client.view.MAMLayoutInflater to a test Java class net.dot.android.test.MyLayoutInflater that extends android.view.LayoutInflater.

I introduced a new test run configuration "IsAssignableFrom" to leverage the new property -p:_AndroidIsAssignableFromCheck=false.

After this is merged, I'll need to manually port this to main for .NET 10. Various files have moved around there; we can use RuntimeFeature.cs, etc.

… hatch

Context: https://github.com/jonathanpeppers/IntuneReproNet9
Context: 35f41dc
Context: 9a27140

.NET 9 introduced a Java "instanceof" check for multiple reasons:

    if (!JniEnvironment.Types.IsAssignableFrom (handleClass, typeClass)) {
        return null;
    }

The problem with this check, is that it fails in combination with the
package:

    <PackageReference Include="Microsoft.Intune.Maui.Essentials.android" Version="11.0.0-develop" />

`LayoutInflater.From (Context)` returns `null` due to:

    Handle 0x7f346ad02d is of type 'com/android/internal/policy/PhoneLayoutInflater' which is not assignable to
'com/microsoft/intune/mam/client/view/MAMLayoutInflater'

To solve this:

* Introduce `-p:_AndroidIsAssignableFromCheck=false`
  to disable the check, defaulting to `true` for .NET 9+.

* Add a test that calls `LayoutInflater.From (Context)` and
  verify it returns non-null.

* Add a test entry in `Remaps.xml` to remap
  `com.microsoft.intune.mam.client.view.MAMLayoutInflater`
  to a test Java class `net.dot.android.test.MyLayoutInflater`
  that extends `android.view.LayoutInflater`.

I introduced a new test run configuration "IsAssignableFrom"
to leverage the new property `-p:_AndroidIsAssignableFromCheck=false`.

After this is merged, I'll need to manually port this to main for .NET
10. Various files have moved around there; we can use `RuntimeFeature.cs`, etc.
Comment on lines +13 to +17
<RuntimeHostConfigurationOption Include="Microsoft.Android.Runtime.RuntimeFeature.IsAssignableFromCheck"
Condition="'$(_AndroidIsAssignableFromCheck)' != ''"
Value="$(_AndroidIsAssignableFromCheck)"
Trim="true"
/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to set even in Debug mode.

Comment on lines 47 to +48
<_AndroidRemapMembers Include="Remaps.xml" />
<_AndroidRemapMembers Include="IsAssignableFromRemaps.xml" Condition=" '$(_AndroidIsAssignableFromCheck)' == 'false' " />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsAssignableFromRemaps.xml is in its own file, because we have a couple tests that need to use the real Android LayoutInflater.

We run only the Intune category under -p:_AndroidIsAssignableFromCheck=false.

@jonathanpeppers
Copy link
Member Author

New test passes, things look good:
image

The log messages say:

09-10 16:19:41.218  8179  8200 I DOTNET  : LayoutInflaterTest: TypeManager.IsAssignableFromCheck=False
09-10 16:19:41.228  8179  8200 I monodroid-assembly: typemap: unable to find mapping to a managed type from Java type 'com/android/internal/policy/PhoneLayoutInflater' (hash 0x30a62d52bedc334d)
...
09-10 16:19:41.234  8179  8200 D monodroid-assembly: typemap: java type 'android/view/LayoutInflater' corresponds to managed token id 33554672 (0x20000f0)
...
09-10 16:19:41.235  8179  8200 D monodroid-assembly: typemap: type with token 33554679 (0x20000f7) in module {C848E954-4790-4169-B1F4-1EB5C125D804} (Mono.Android) corresponds to Java type 'android/view/LayoutInflater'
...
09-10 16:19:41.300  8179  8200 D monodroid-assembly: Handle 0x11 is of type 'com/android/internal/policy/PhoneLayoutInflater' which is not assignable to 'net/dot/android/test/MyLayoutInflater'
...
09-10 16:19:41.710  8179  8200 I NUnit   : 	Passed

@jonathanpeppers jonathanpeppers marked this pull request as ready for review September 10, 2025 16:49
@jonathanpeppers
Copy link
Member Author

This looks green, there are just a couple networking-related failures we can ignore:

System.Net.Http.HttpRequestException : net_http_message_not_success_statuscode_reason, 503, Service Temporarily Unavailable

@jonathanpeppers jonathanpeppers merged commit f395493 into release/9.0.1xx Sep 11, 2025
55 of 57 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/net9-remap branch September 11, 2025 14:09
jonathanpeppers added a commit that referenced this pull request Sep 11, 2025
Forward port of: #10473
Context: https://github.com/jonathanpeppers/IntuneReproNet9
Context: 35f41dc
Context: 9a27140

.NET 9 introduced a Java "instanceof" check for multiple reasons:

    if (!JniEnvironment.Types.IsAssignableFrom (handleClass, typeClass)) {
        return null;
    }

The problem with this check, is that it fails in combination with the
package:

    <PackageReference Include="Microsoft.Intune.Maui.Essentials.android" Version="11.0.0-develop" />

`LayoutInflater.From (Context)` returns `null` due to:

    Handle 0x7f346ad02d is of type 'com/android/internal/policy/PhoneLayoutInflater' which is not assignable to
'com/microsoft/intune/mam/client/view/MAMLayoutInflater'

To solve this:

* Introduce `-p:_AndroidIsAssignableFromCheck=false`
  to disable the check, defaulting to `true` for .NET 9+.

* Add a test that calls `LayoutInflater.From (Context)` and
  verify it returns non-null.

* Add a test entry in `IsAssignableFromRemaps.xml` to remap
  `com.microsoft.intune.mam.client.view.MAMLayoutInflater`
  to a test Java class `net.dot.android.test.MyLayoutInflater`
  that extends `android.view.LayoutInflater`.

I introduced a new test run configuration "IsAssignableFrom"
to leverage the new property `-p:_AndroidIsAssignableFromCheck=false`,
and only run the `Intune` category.
grendello pushed a commit that referenced this pull request Sep 15, 2025
…tch (#10475)

Forward port of: #10473
Context: https://github.com/jonathanpeppers/IntuneReproNet9
Context: 35f41dc
Context: 9a27140

.NET 9 introduced a Java "instanceof" check for multiple reasons:

    if (!JniEnvironment.Types.IsAssignableFrom (handleClass, typeClass)) {
        return null;
    }

The problem with this check, is that it fails in combination with the package:

    <PackageReference Include="Microsoft.Intune.Maui.Essentials.android" Version="11.0.0-develop" />

`LayoutInflater.From (Context)` returns `null` due to:

    Handle 0x7f346ad02d is of type 'com/android/internal/policy/PhoneLayoutInflater' which is not assignable to 'com/microsoft/intune/mam/client/view/MAMLayoutInflater'

To solve this:

* Introduce `-p:_AndroidIsAssignableFromCheck=false` to disable the check, defaulting to `true` for .NET 9+.

* Add a test that calls `LayoutInflater.From (Context)` and verify it returns non-null.

* Add a test entry in `IsAssignableFromRemaps.xml` to remap `com.microsoft.intune.mam.client.view.MAMLayoutInflater` to a test Java class `net.dot.android.test.MyLayoutInflater` that extends `android.view.LayoutInflater`.

I introduced a new test run configuration "IsAssignableFrom" to leverage the new property `-p:_AndroidIsAssignableFromCheck=false`, and only run the `Intune` category.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants