Skip to content

[release/10.0.1xx-preview6] Merge main into release/10.0.1xx-preview6. #23085

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

Open
wants to merge 6 commits into
base: release/10.0.1xx-preview6
Choose a base branch
from

Conversation

rolfbjarne
Copy link
Member

No description provided.

rolfbjarne and others added 3 commits June 19, 2025 13:27
… an object in the finalizer queue. (#23072)

The following happens:

1. An instance of a custom NSObject subclass is created, with both a native instance
   and the corresponding managed wrapper.

2. Native code creates a weak reference to the native instance.

3. No other managed code references the managed instance, and there's no non-weak
   native reference to the native instance, so the GC schedules the managed instance
   for finalization.

4. Native code fetches the native instance from the weak reference.

5. Native code thinks it can do whatever it wants with the native instance, because
   it got a perfectly valid (and retained) native instance. Unfortunately, there's no way
   to stop the managed instance from being finalized (which happens on a background
   thread anyway, so there's no thread-safe way to do it), which means havoc ensues.

The most frequent manifestation of this problem has been like this:

    ObjCRuntime.RuntimeException: Failed to marshal the Objective-C object 0x13d566800 (type: Microsoft_Maui_Platform_MauiTextField). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Microsoft.Maui.Platform.MauiTextField' does not have a constructor that takes one NativeHandle argument).
       at ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
       at ObjCRuntime.Runtime.ConstructNSObject[NSObject](IntPtr , Type , MissingCtorResolution , IntPtr , RuntimeMethodHandle )
       at ObjCRuntime.Runtime.ConstructNSObject[NSObject](IntPtr , Type , MissingCtorResolution )
       at ObjCRuntime.Runtime.ConstructNSObject(IntPtr , IntPtr , MissingCtorResolution )
       at ObjCRuntime.Runtime.GetNSObject(IntPtr , MissingCtorResolution , Boolean )
       at ObjCRuntime.Runtime.GetNSObject(IntPtr )
       at ObjCRuntime.Runtime.InvokeConformsToProtocol(IntPtr , IntPtr )
       at ObjCRuntime.Runtime.invoke_conforms_to_protocol(IntPtr obj, IntPtr protocol, IntPtr* exception_gchandle)
       Exception_EndOfInnerExceptionStack

but other problems can also occur.

This is a rather complicated issue to fix, because:

* There's no way to be notified when native code creates a weak reference to a
  native instance.
* There's not even a way to know if anybody has a weak reference to a native
  instance.
* I also looked into manually clearing the weak references for a native
  instance, but that's not possible either.

However, it is possible to basically say "nope!" when native code tries to
fetch a native instance from a weak reference:

We override the '[NSObject retainWeakReference]' method for all custom
NSObject subclasses, and return FALSE if the corresponding managed object has
been scheduled for finalization (otherwise call the base class implementation).

The ['[NSObject retainWeakReference]'][1] method is public, but it's not
documented how it's supposed to behave. Fortunately, the corresponding [source
code][2] is public, so we can figure out the semantics ourselves: return
`TRUE` if the object can be / was retained, `FALSE` otherwise.

* Fixes #21648.
* Fixes dotnet/maui#28261.
* Fixes #19076.

Might also fix the following issues:

* #22867
* #19579
* #4207
* https://bugzilla.xamarin.com/show_bug.cgi?id=34242 (https://web.archive.org/web/20170630214134/https://bugzilla.xamarin.com/show_bug.cgi?id=34242)

[1]: https://developer.apple.com/documentation/foundation/nsproxy/retainweakreference
[2]: https://github.com/apple-oss-distributions/objc4/blob/f126469408dc82bd3f327217ae678fd0e6e3b37c/runtime/NSObject.mm#L539-L541
…1: Build ID 11793019 (#23081)

This is the pull request automatically created by the OneLocBuild task in the build process to check-in localized files generated based upon translation source files (.lcl files) handed-back from the downstream localization pipeline. If there are issues in translations, visit https://aka.ms/icxLocBug and log bugs for fixes. The OneLocBuild wiki is https://aka.ms/onelocbuild and the localization process in general is documented at https://aka.ms/AllAboutLoc.

---------
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

mauroa and others added 2 commits June 19, 2025 16:01
Brings important changes around Xamarin deprecation and Mac paths:

- Updated Xamarin.Messaging to 18.0.136-g9e200fbc6d
- Added target before SayHello to set default Messaging context path values
- Adapted code to Messaging API changes
- IL merge BouncyCastle.Cryptography (new SSH.NET dependency)
- Updated from old Xamarin path to new maui path in test scripts
- Fixed CompileNativeCode to correctly resolve dotnet packs paths

---------

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
@rolfbjarne rolfbjarne requested review from emaf and mauroa as code owners June 19, 2025 14:09
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #2084384] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #2084384] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

✅ API diff vs stable

.NET ( No breaking changes )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #2084384] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #2084384] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #2084384] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #2084384] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #2084384] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #2084384] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 1 tests failed, 119 tests passed.

Failures

❌ monotouch tests (macOS) [attempt 3]

1 tests failed, 11 tests passed.
  • monotouch-test/macOS/Release (NativeAOT, ARM64): BuildFailure

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 10 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 20843847e4e678166203e06a32b8da29d0961f3f [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants