Skip to content

Printing throws an exception when PublishAot is true #2390

@DHancock

Description

@DHancock

Description

Adding <PublishAot>true</PublishAot> to the project causes a NotSupportedException to be thrown when calling the IPrintManagerInterop method ShowPrintUIForWindowAsync(). It occurs in debug, release and publish builds.

The exception message is:

Cannot retrieve a helper type for generic public type 'Windows.Foundation.IAsyncOperation`1[System.Boolean]'.

With a call stack of:

 	[System.NotSupportedException thrown]	
>	[Exception] WinRT.Runtime.dll!WinRT.TypeExtensions.FindHelperType(System.Type type, bool throwIfNotAotSupported) Line 38	C#
 	[Exception] WinRT.Runtime.dll!WinRT.IWinRTObject.IsInterfaceImplementedFallback(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) Line 152	C#
 	[Exception] WinRT.Runtime.dll!WinRT.IWinRTObject.System.Runtime.InteropServices.IDynamicInterfaceCastable.IsInterfaceImplemented(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) Line 30	C#
 	ntdll.dll!NtWaitForSingleObject()	Unknown
 	KernelBase.dll!WaitForSingleObjectEx()	Unknown
 	ntdll.dll!RtlpExecuteHandlerForUnwind()	Unknown
 	ntdll.dll!RtlUnwindEx()	Unknown
 	ntdll.dll!RtlUnwind()	Unknown
 	ntdll.dll!RtlpExecuteHandlerForException()	Unknown
 	ntdll.dll!RtlDispatchException()	Unknown
 	ntdll.dll!KiUserExceptionDispatch()	Unknown
 	KernelBase.dll!RaiseException()	Unknown
 	[Managed to Native Transition]	
 	System.Private.CoreLib.dll!System.Runtime.CompilerServices.CastHelpers.ChkCastAny_NoCacheLookup(void* toTypeHnd, object obj) Line 52	C#
 	Microsoft.Windows.SDK.NET.dll!Windows.Graphics.Printing.PrintManagerInterop.ShowPrintUIForWindowAsync(nint appWindow)	Unknown

The exception seems to be thrown after the print dialog is opened and the dialog still appears to work as expected, apart from that it's now fire and forget.

I don't know if this is an interop issue or winrt issue, but since you're first in the stack trace...

Steps To Reproduce

Run the attached project and click print (its an updated version of https://github.com/marb2000/PrintSample).

PrintSample-master.zip

Expected Behavior

.

Version Info

CsWinRT: 2.2.0
.Net SDK: 10.0.201

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions