IronPrint中的ShowPrintDialog行为(2024.9之后)
ShowPrintDialog 和 ShowPrintDialogAsync 在不受支持的目标框架上调用时不再抛出异常。 自版本 2024.9 起,它们记录警告并改为回退到 PrintAsync()。
在此更改之前,没有兼容的 TargetFramework 调用任一方法会引发以下错误:
System.AggregateException: 'One or more errors occurred.
(Please try Print/PrintAsync since ShowPrintDialog/ShowPrintDialogAsync in NET Core or NET Standard,
it required UI component so please set more specific OS TargetFrameworks
e.g. net462; net472; net7.0-windows; net7.0-macos; net7.0-maccatalyst; net7.0-android)'
对话框方法需要一个UI组件,而普通的.NET Core或.NET Standard目标中不可用。 早期版本将此视为严重故障并抛出。 该异常在运行时具有破坏性,因此在 2024.9 中故意更改了该行为。
解决方案
回退是自动的,但您可以通过选择正确的目标来控制运行的路径。
1. 依赖自动回退
在不支持的框架下,调用现在会记录警告并路由到 PrintAsync() 而不是抛出。 现有代码继续运行而不会崩溃,但没有出现打印对话框。
2. 选择支持UI的框架以显示对话框
要获取实际的打印对话框,请针对包含UI支持的特定操作系统目标进行构建:
<TargetFrameworks>net462;net472;net7.0-windows;net7.0-macos;net7.0-maccatalyst;net7.0-android</TargetFrameworks>
<TargetFrameworks>net462;net472;net7.0-windows;net7.0-macos;net7.0-maccatalyst;net7.0-android</TargetFrameworks>
在这些框架中的一个到位后,ShowPrintDialog 和 ShowPrintDialogAsync 按预期显示对话框。

