[mono] Preserve FirstChanceExceptionEventArgs ctor#68235
Merged
akoeplinger merged 2 commits intodotnet:mainfrom Apr 20, 2022
Merged
[mono] Preserve FirstChanceExceptionEventArgs ctor#68235akoeplinger merged 2 commits intodotnet:mainfrom
akoeplinger merged 2 commits intodotnet:mainfrom
Conversation
The runtime is creating the exception so we need to preserve it. See dotnet/android#6626
Contributor
|
We try to avoid using descriptors if possible. I think a better fix would be to add it as DynamicDependencyAttribute to |
stephentoub
approved these changes
Apr 20, 2022
Member
Author
|
@marek-safar I tried but it doesn't compile: |
Contributor
Looks like bad API design but it should be possible to use the underlying target. Try this instead [field: DynamicDependency ()] |
Member
Author
|
@marek-safar that worked :) I switched over UnhandledExceptionEventArgs too |
marek-safar
approved these changes
Apr 20, 2022
Member
Author
|
/backport to release/6.0 |
Contributor
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2196008785 |
directhex
pushed a commit
to directhex/runtime
that referenced
this pull request
Apr 21, 2022
The runtime is creating the exception so we need to preserve it. See dotnet/android#6626 While looking at this I noticed that `FirstChanceExceptionEventArgs` is in ExceptionNotification.cs for some reason, fixed the filename to match the type name. Use DynamicDependency for preserving `FirstChanceExceptionEventArgs` and `UnhandledExceptionEventArgs`
jonpryor
pushed a commit
to dotnet/android
that referenced
this pull request
Apr 21, 2022
) Fixes: #6626 Context: dotnet/runtime#68235 If you create a .NET 6 app whichs ubscribes to the [`AppDomain.FirstChanceException`][0] event: partial class MainActivity { protected override void OnCreate (Bundle? savedInstanceState) { AppDomain.CurrentDomain.FirstChanceException += (o, e) => { Console.WriteLine ("First chance exception!"); }; } } and has a way to cause an exception to be thrown: partial class MainActivity { public override void OnBackPressed() => throw new Exception ("wee?"); } and is built in Release configuration with Trimming enabled, then the app will crash when the exception is thrown (in the above case, by launching the app and then pressing the Back button): E companyname.fo: * Assertion at /__w/1/s/src/mono/mono/metadata/object.c:4179, condition `ctor' not met The cause of the crash is that the linker removes the [`FirstChanceExceptionEventArgs(Exception)`][1] constructor. This was fixed in dotnet/runtime#68235 by using appropriate `[DynamicDependency]` attributes. However, this runtime fix is unlikely to be released before our next RC. Add a workaround by updating `src/Microsoft.Android.Sdk.ILLink/PreserveLists/System.Private.CoreLib.xml` so that the linker won't remove the `FirstChanceExceptionEventArgs(Exception)` constructor. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.firstchanceexception?view=net-6.0 [1]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.exceptionservices.firstchanceexceptioneventargs.-ctor?view=net-6.0
jonathanpeppers
pushed a commit
to dotnet/android
that referenced
this pull request
Apr 21, 2022
) Fixes: #6626 Context: dotnet/runtime#68235 If you create a .NET 6 app whichs ubscribes to the [`AppDomain.FirstChanceException`][0] event: partial class MainActivity { protected override void OnCreate (Bundle? savedInstanceState) { AppDomain.CurrentDomain.FirstChanceException += (o, e) => { Console.WriteLine ("First chance exception!"); }; } } and has a way to cause an exception to be thrown: partial class MainActivity { public override void OnBackPressed() => throw new Exception ("wee?"); } and is built in Release configuration with Trimming enabled, then the app will crash when the exception is thrown (in the above case, by launching the app and then pressing the Back button): E companyname.fo: * Assertion at /__w/1/s/src/mono/mono/metadata/object.c:4179, condition `ctor' not met The cause of the crash is that the linker removes the [`FirstChanceExceptionEventArgs(Exception)`][1] constructor. This was fixed in dotnet/runtime#68235 by using appropriate `[DynamicDependency]` attributes. However, this runtime fix is unlikely to be released before our next RC. Add a workaround by updating `src/Microsoft.Android.Sdk.ILLink/PreserveLists/System.Private.CoreLib.xml` so that the linker won't remove the `FirstChanceExceptionEventArgs(Exception)` constructor. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.firstchanceexception?view=net-6.0 [1]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.exceptionservices.firstchanceexceptioneventargs.-ctor?view=net-6.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The runtime is creating the exception so we need to preserve it.
See dotnet/android#6626
While looking at this I noticed that
FirstChanceExceptionEventArgsis in ExceptionNotification.cs for some reason, fixed the filename to match the type name.Use DynamicDependency for preserving
FirstChanceExceptionEventArgsandUnhandledExceptionEventArgs