Wpf: 'Unable to load DLL PresentationNative_v0400.dll' exception is thrown if PrintDialog class is used

Created on 6 Mar 2019  路  4Comments  路  Source: dotnet/wpf

  • .NET Core Version: 3.0.100-preview4-010591
  • Windows version: 1809 (17763.316)
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: no info

    Problem description:
    Exception is thrown if the PrintDialog class is used

    Actual behavior:
    Exception is thrown

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'PresentationNative_v0400.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
  Source=System.Printing
  StackTrace:
   at MS.Internal.PrintWin32Thunk.Win32ApiThunk.PresentationNativeUnsafeNativeMethods.IsPrintPackageTargetSupportedImpl()
   at MS.Internal.PrintWin32Thunk.Win32ApiThunk.PresentationNativeUnsafeNativeMethods.IsPrintPackageTargetSupported()
   at System.Printing.PrintQueue.IsXpsOMPrintingSupported()
   at System.Windows.Xps.XpsDocumentWriter.BeginWrite(Boolean batchMode, Boolean asyncMode, Boolean setPrintTicketHandler, PrintTicket printTicket, PrintTicketLevel printTicketLevel, Boolean printJobIdentifierSet)
   at System.Windows.Xps.XpsDocumentWriter.Write(Visual visual, PrintTicket printTicket)
   at System.Windows.Controls.PrintDialog.PrintVisual(Visual visual, String description)
   at WpfApp2.MainWindow.ButtonExit_Click(Object sender, RoutedEventArgs e) in C:\Users\ovcharov.pavel\source\repos\WpfApp2\WpfApp2\MainWindow.xaml.cs:line 26
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.ReInvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at WpfApp2.App.Main()

Expected behavior:
No exception should be thrown

Minimal repro:
Try to execute the following code
new PrintDialog().PrintVisual(new Button(), "test");

issue-type-bug

All 4 comments

Thanks for reporting this - I hit this independently recently as well. We had renamed PresentationNative_v0400.dll to PresentationNative_cor3.dll in .NET Core 3.0.

Turns out that there are a few P/Invokes from System.Printing.dll into PresentationNative that had not been updated to account for this change in name.

In addition to this, I also found a few more places where we continue to do ETW tracing based on old names (esp. wpfgfx_v0400.dll - which has now been renamed to wpfgfx_cor3.dll). This is likely benign at this point, but needs to be fixed before RTM as well.

This should have been fixed now. Would you mind trying a recent Preview build from https://github.com/dotnet/core-sdk?

Yes, this was fixed in our internal repo last week. Everything should be working in recent builds.

Thanks, @pavelovcharov. There were some incorrect Platform Invoke declarations that have been fixed. Please reactivate if the bug appears again.

Was this page helpful?
0 / 5 - 0 ratings