dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.81k stars 196 forks source link

ShellLink cannot be used in AOT situations #487

Closed MakesYT closed 2 months ago

MakesYT commented 2 months ago

Describe the bug and how to reproduce Minimal example https://github.com/MakesYT/ShellLinkAOT

var shellLink = ShellLink.Create(
    $"{Environment.GetFolderPath(Environment.SpecialFolder.Programs)}\\1.lnk",
    $"{Environment.GetFolderPath(Environment.SpecialFolder.Programs)}\\1.lnk",null);

What code is involved

Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program. The body of method 'Void CShellLinkW..ctor()' is invalid.
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID, String) + 0x36
   at Vanara.PInvoke.Shell32.CShellLinkW..ctor() + 0xf
   at Vanara.Windows.Shell.ShellLink..ctor() + 0x14
   at Vanara.Windows.Shell.ShellLink..ctor(String, String, String, String) + 0x11
   at Vanara.Windows.Shell.ShellLink.Create(String, String, String, String, String) + 0x33
   at Program.<Main>$(String[] args) + 0x45

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

dahall commented 2 months ago

AOT does not support COM, upon which the ShellLink class depends.