TaskScheduler
TaskScheduler copied to clipboard
AOT publishing
Describe the bug Exceptions on runnig AOT build
To Reproduce Steps to reproduce the behavior:
- Create project with AOT publishing
- Use any functionality from TaskScheduler
- Publish
- Run
- See exception
Unhandled exception. System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.InvalidProgramException: Common Language Runtime detected an invalid program. The body of method 'Void Microsoft.Win32.TaskScheduler.V2Interop.TaskSchedulerClass..ctor()' is invalid.
at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID, String) + 0x40
at Microsoft.Win32.TaskScheduler.V2Interop.TaskSchedulerClass..ctor() + 0x15
at Microsoft.Win32.TaskScheduler.TaskService.Connect() + 0x150
at Microsoft.Win32.TaskScheduler.TaskService.get_Instance() + 0x63
at Microsoft.Win32.TaskScheduler.TaskService..cctor() + 0xc0
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xba
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x13c
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnGCStaticBase(StaticClassConstructionContext*, Object) + 0xd
at Microsoft.Win32.TaskScheduler.TaskService.get_Instance() + 0xcd
at Program.<Main>$(String[] args) + 0xf
Expected behavior Exception free build
Screenshots
Additional context Minimal example
Code for testing:
using Microsoft.Win32.TaskScheduler;
TaskService.Instance.AddTask("Test", QuickTriggerType.TaskRegistration, "myprogram.exe", "-a arg");
Solution Possible solution is to rewrite from ComImport to ComWrappers
Thank you. I have looked into this and it will require a pretty substantial rewrite. I eventually will look into it, but it will not happen soon. If you would like to help with the work and submit a PR, that will be the fastest resolution.