Skip to content

AOT publishing #1011

@ia-alpatov

Description

@ia-alpatov

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions