Open AraHaan opened 4 years ago
Registering a handler for AppDomain.UnhandledException on .NET Framework does not require SecurityPermissionAttribute if the application domain already grants full trust to all assemblies; see AppDomain.IsFullyTrusted. So if you don't need to support partial-trust scenarios, you can delete that.
Your code sample seems to be using C# 8, which is not supported on .NET Framework anyway.
https://github.com/dotnet/dotnet-api-docs/pull/4384 is removing the SecurityPermissionAttribute from the AppDomain.UnhandledException example.
It is targeting .NET Core 3.1 and uses that to use that event for unhandled exceptions.
But I also plan to switch it to net5.0
eventually though.
With DE0002 being given to projects that uses
using System.Security.Permissions;
just to be able to register an unhandled exception event and to control appdomains (which registering that event requires). How else are we going to be able to use that event without using the CAS that is says not to use?I think the documentation should include ways of using that event without using CAS then...
consider a minimal example being a console application like so:
dotnet new console
and then add the packageMicrosoft.DotNet.Analyzers.Compatibility
at version0.2.12-alpha
.namespace ConsoleApplication1 { public static class Program { [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)] public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); throw new Exception("Unhandled.") }
}