TaskScheduler icon indicating copy to clipboard operation
TaskScheduler copied to clipboard

AOT publishing

Open ia-alpatov opened this issue 5 months ago • 1 comments

Describe the bug Exceptions on runnig AOT build

To Reproduce Steps to reproduce the behavior:

  1. Create project with AOT publishing
  2. Use any functionality from TaskScheduler
  3. Publish
  4. Run
  5. 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

publish settings exception

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

ia-alpatov avatar Aug 10 '25 02:08 ia-alpatov

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.

dahall avatar Aug 12 '25 15:08 dahall