Wpf: Unable to load DLL 'wpfgfx_cor3.dll' or one of its dependencies

Created on 7 Oct 2019  Â·  16Comments  Â·  Source: dotnet/wpf

@pieterphilippaerts commented on Sat Oct 05 2019

I've written a .NET Core 3 WPF application and it works perfectly on my development machine (Windows 10, x64). Unfortunately, when I try to deploy it on my test computer (Windows 8.1, x86) I get an error.

When I start the application, it starts executing (it creates a few files and directories) and I also see the splash screen. However, when the main window of the application gets loaded, I get the following error:

System.Windows.Markup.XamlParseException: 'Add value to collection of type 'System.Windows.Controls.UIElementCollection' threw an exception.' Line number '17' and line position '10'.
---> System.DllNotFoundException: Unable to load DLL 'wpfgfx_cor3.dll' or one of its dependencies: The specified procedure could not be found. (0x8007007F)
at System.Windows.Media.MediaContextNotificationWindow.MilContent_AttachToHwnd(IntPtr hwnd)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Visual.VerifyAPIReadWrite()
at System.Windows.Media.VisualCollection.Add(Visual visual)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement element)
at System.Windows.Controls.UIElementCollection.Add(UIElement element)
at System.Windows.Controls.UIElementCollection.System.Collections.IList.Add(Object value)
at System.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object instance, Object item)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(Object collection, XamlType collectionType, Object value, XamlType valueXamlType)
--- End of inner exception stack trace ---
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at PieterP.ScoreSheet.GUI.Views.MainWindow.InitializeComponent() in C:\Users\skydr\source\repos\scoresheet\src\gui\PieterP.ScoreSheet.GUI\Views\MainWindow.xaml:line 1
at PieterP.ScoreSheet.GUI.Views.MainWindow..ctor() in C:\Users\skydr\source\repos\scoresheet\src\gui\PieterP.ScoreSheet.GUI\Views\MainWindow.xaml.cs:line 26
at PieterP.ScoreSheet.GUI.App.OnStartup(StartupEventArgs e) in C:\Users\skydr\source\repos\scoresheet\src\gui\PieterP.ScoreSheet.GUI\App.xaml.cs:line 52
at System.Windows.Application.<.ctor>b__1_0(Object unused)
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)

Apparently, the problem is caused because it cannot load wpfgfx_cor3.dll, which sounds like one of the runtime dlls. I don't know whether the problem is Windows 8.1 or x86 (or the combination), or something else... In any case, the .NET Core Runtime and the .NET Core Desktop pack both installed correctly.


@scalablecory commented on Mon Oct 07 2019

@grubioe @dagood


@dagood commented on Mon Oct 07 2019

Moving to WPF. (Unfortunately not the GitHub way because I don't have write permission there. 😕)

Most helpful comment

Thank you for this info. Installing KB2999226 works fine.

All 16 comments

@pieterphilippaerts can you add a repro app that can help us troubleshoot? Thanks

WpfApp1.zip
Hello Gustavo,

Any WPF application seems to crash on my x86 Win8.1, including the default application Visual Studio creates for you when you create a new .NET core WPF project. I've uploaded a ZIP file that contains the basic WPF template application and the x86 build output.

When I run the WPF template, I get the exception below. The stack trace is slightly different, but it comes down to the same problem.

Unhandled exception. System.DllNotFoundException: Unable to load DLL 'wpfgfx_cor3.dll' or one of its dependencies: The specified procedure could not be found. (0x8007007F)
at System.Windows.Interop.HwndTarget.VisualTarget_AttachToHwnd(IntPtr hwnd)
at System.Windows.Interop.HwndTarget.AttachToHwnd(IntPtr hwnd)
at System.Windows.Interop.HwndTarget..ctor(IntPtr hwnd)
at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
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.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Objectstate)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Objectstate)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(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.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
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.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()
at WpfApp1.App.Main()

Note that I have the following packages installed on the machine:

  • Microsoft Windows Desktop Runtime (3.0.0)
  • Microsoft .NET Core Runtime (3.0.0)
  • Microsoft Visual C++ 2015-2019 Redistributable
    I even installed the .NET Core SDK, but that didn't help either.

I can actually find the DLL file on the system (in c:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\3.0.0).

I did some further testing, and I found that the problem only occurs if I publish the application as "Framework Dependent"! If I publish is as "Self-contained", the app runs fine (and I see the wpfgfx_cor3.dll file in the app's directory).

Do you have the Windows KB's listed in the .NET Core Prerequisites article installed on the aforementioned Windows 8.1 system?

If you do, and you still get crashes, would you mind sharing a full user mode crash dump ?

Do you have the Windows KB's listed in the .NET Core Prerequisites article installed on the aforementioned Windows 8.1 system?

Thanks Vatsan! It turned out that there was a problem with the Windows Update on that machine. It reported no new updates, but it simply wasn't working at all (apparently this is a common problem on Windows 8.1).

Anyway, I manually installed a number of updates, including KB2999226 that was mentioned on the .NET Core Prerequisites, and it works now.

If I may offer a suggestion: can you add the link to the prerequisites page on the .NET Core download page? None of the download pages (https://dotnet.microsoft.com/download, https://dotnet.microsoft.com/download/dotnet-core and https://dotnet.microsoft.com/download/dotnet-core/3.0) mention anything about these prerequisites. If I saw the link on one of these pages, my penny might have dropped a little bit faster :-)

Thanks!

@richlander Can we get pre-reqs mentioned on the above pages as part of the documentation push?

@leecow @rowanmiller is there a current way we expect people to find the .NET Core Prerequisites article when downloading runtimes? Can this be added to the website?

(For context, the only current place I know about prereqs being listed on the dotnet site are the Linux prereqs on the "thank you" page for downloading binaries: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-linux-x64-binaries.)

@dagood Can we detect and warn about missing prereqs in the installer?

I'm not sure. We have the ancient issue https://github.com/dotnet/core-setup/issues/191 tracking that, I'll ping some folks to triage it. Would certainly be a nice way to handle it.

I'm not sure. We have the ancient issue dotnet/core-setup#191 tracking that, I'll ping some folks to triage it. Would certainly be a nice way to handle it.

I have a small tool at https://github.com/vatsanm/checknetcoreprereqs that can check whether the prereqs are present. You can incorporate it into the installer if you'd like.

I am having trouble following the thread. Can someone explicitly list the pre-reqs required on (I believe) Win 8.1? I am happy to shuttle those to docs.

@richlander https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore30#net-core-dependencies has a section for Windows 7 and 8.1, its just not discoverable during the normal download/installation process a user goes through

I've solved this problem with installing the Visual Studio 2015-2019 Runtimes:

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Installing the Visual Studio 2015 Runtimes did not work for me:

https://www.microsoft.com/en-us/download/details.aspx?id=48145

@richlander - the ask is to link to the all up pre-reqs page from the download page. Perhaps best to track this as a enhancement request in the Core repo?

@ms579984 We don't require Visual Studio Runtime as a prerequisite. What .NET Core requires are these:

  • Universal CRT aka UCRT (which is not the same thing as Visual Studio Runtime aka vcrt)

    • UCRT comes preinstalled on Windows 10

    • For older platforms you can acquire it by installing KB2999226

  • KB2533623 , which provides LOAD_LIBRARY_SEARCH_SYSTEM32 flag support in LoadLibraryEx API, AddDllDirectory, SetDefaultDllDirectories and RemoveDllDirectory

    • This support exists in Win8 and later. KB2533623 is needed for Win7 (and the corresponding server OS - Windows Server 2008 R2) only.

Previous preview versions of .NET Core 3.0 used to require _Visual Studio Runtime_, but that requirement was removed a long time ago - https://github.com/dotnet/wpf/issues/37.

Thank you for this info. Installing KB2999226 works fine.

my .net core 3.1 application encount this issue too, install KB2999226 solved problem。
but .net core 3.0 application does not need this KB。
os: Win7 Pro x64

Was this page helpful?
0 / 5 - 0 ratings