Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[d16-6] [appkit] Fix
NSApplication
with custom initialization (#7958)
Custom initialization of Xamarin.Mac is tricky. You can easily start using ObjC features before everything is ready / loaded into memory. In contrast a _normal_ XM application, from an app bundle, already has a lot of things loaded into memory when it starts to initialize. This means that some things can work _by chance_ due to timing and that semi-related (and correct) changes could affect your _lucky_ timings. Such a semi-related change was a239fa9#diff-4aa19167162888aec0ccc2261a7ddbd3 In #7932 the attached code ```csharp NSApplication.IgnoreMissingAssembliesDuringRegistration = false; ``` triggers the `.cctor` which means that `class_ptr` is initialized. Note: That's not fully correct/safe since `Init` is not been called but that's a different issue... Anyway the dual calls that existed before was enough to hide the first (which failed but triggered the rest of the native initialization). That extra call made older XM version works (with attached code). So in this (#7932) case our generated code ```csharp static readonly IntPtr class_ptr = Class.GetHandle ("NSApplication"); ``` happens too early. Now that cannot be changed because * it's how .net `readonly` works * existing/correct code depends on this * it depends on native side (being loaded/initialized/ready) but we can **add** to this and make `Init` safer to use by duplicating the call _only if_ the original call had failed. Of course the generated code has the `class_ptr` field as `readonly`... ``` error CS0198: A static readonly field cannot be assigned to (except in a static constructor or a variable initializer) ``` so we need to use reflection to achieve this (but that cost will occur if the original initialization failed) Fix #7932
- Loading branch information
ef273a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚧 Experimental DDFun pipeline
🔥 Device tests completed (Failed) on iOS-DDFun on Azure DevOps(iOS-DDFun) 🔥
Test results
14 tests failed, 136 tests passed.
Failed tests
ef273a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Device tests passed on iOS on Azure DevOps(iOS): Html Report ✅
🎉 All 150 tests passed 🎉
ef273a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Build was (probably) aborted
🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Test run, Test run' 🔥
✅ Build succeeded
✅ Packages:
✅ API Diff (from stable)
✅ API Diff (from PR only) (no change)
✅ Generator Diff (no change)
🔥 Test run failed 🔥
Test results
4 tests failed, 179 tests passed.
Failed tests
ef273a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 Device tests completed (Failed) on TvOS on Azure DevOps(TvOS): Html Report 🔥
Test results
14 tests failed, 136 tests passed.
Failed tests
ef273a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 Device tests completed (Failed) on iOS32b on Azure DevOps(iOS32b): Html Report 🔥
Test results
# Test run in progress: Running: 1, RunQueued: 11, Succeeded: 128, Failed: 14, Ignored: 1100, Crashed: 1, TimedOut: 3, BuildFailure: 3
Failed tests