WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (2023)

Table of Contents
2 answers Activity Videos

asked 2023-01-04T14:45:07.963+00:00 by

WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (1)

Arni Jonsson 1Reputation point

Hello,

I have a C# WPF .NET application that uses a 3rd party SDK called PaymentSDK.dll which I include and reference inside the application project.
The application runs all fine and smooth on my development computer and also in some of my customer computers in Production/Release.
However on some computers the application runs into the infamous error: "Could not load file or assembly 'PaymentSdk.dll' or one of its dependencies. The specified module could not be found.".

I have found many threads where this error is discussed but none have described my issue.

I took a look in the AppData folder in my client's computer and it seems that the PaymentSDK is there.
I took a look at the PaymentSDK's manifest file and found the following dependencies and tried to add a BindingRedirect in App.config for all these dependencies like so:

WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (2)

I updated .NET, to 4.8. The SDK requires .NET 4.6+.

I checked the event viewer on the faulting computer and I noticed the following error along with the previous System.IO.FileNotFoundException.

Faulting application name: ReglaPOS2.exe, version: 1.0.0.0, time stamp: 0x639c5f20
Faulting module name: KERNELBASE.dll, version: 10.0.17763.3770, time stamp: 0x21e9d433
Exception code: 0xe0434352
Fault offset: 0x001256b2
Faulting process id: 0x16f0
Faulting application start time: 0x01d9138f01a13723
Faulting application path: C:\<User-Path>\AppData\Local\Apps\2.0\72M7LWOQ.VOJ\L66XQ8J4.DE6\regl..tion_0000000000000000_0003.0008_4e96cbfa5e9538a8\ReglaPOS2.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 919e9aed-305f-4468-a852-009901923425
Faulting package full name:
Faulting package-relative application ID:

I'm not sure if it's connected to the other error.

Do you have any explanations on why it could be happening on some computers and not on others and/or any helpful advice on trying to solve this?

Many thanks,
Earnie

XAML

XAML

A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.

550 questions

0No comments

(Video) How to fix error Could not load file or assembly

0{count} votes

    Sign in to comment

    1. answered 2023-01-04T16:28:21.757+00:00 by

      WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (3)

      Michael Taylor 37,206Reputation points

      What bitness is your EXE being compiled at (x86, x64, AnyCPU)? What is the bitness of the PaymentSDK? If your app is AnyCPU but the PaymentSDK only works in x86 and you attempt to run the app on an x64 machine then it'll fail.

      A versioning issue seems unlikely if it works on some machines and not others but you can quickly rule this out by looking at the assembly version that is deployed on a non-working machine. If the version doesn't match what works on other machines then it is a versioning issue and binding redirects are the solution. But, again, this seems unlikely if it works for some clients.

      The next thing to look at is whether the client machines actually have .NET 4.8 installed or not. The app itself will require CLR v4 but any version of .NET 4.x would work here. However if the app attempts to use something that is only in a later version then it would fail, although I would be a little surprised at the error.

      The event viewer error is a general software error and by itself not useful. However normally .NET reports the actual exception so maybe there are more errors you aren't seeing?

      Finally, take a look at the dependencies that your PlatformSDK relies on. Does it require third party libraries (such as C++) to be installed? If so then you need to ensure they are installed as well. Again I would be a little surprised with the FnF exception but I've seen more bizarre behavior before.

      1. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (4)

        Arni Jonsson 1Reputation point

        (Video) [SOLVED] Debugging System.IO.FileNotFoundException C# Winform

        2023-01-05T16:35:57.153+00:00

        Thanks for the answer!

        The PaymentSDK and the application is compiled at x86 but the faulting computer is x64 which should work, so I suppose I can exclude that.

        I checked the event viewer once more and found the following error where Framework Version is v4.0.xxx which I assume is the .NET version:
        Application: ReglaPOS2.exe
        Framework Version: v4.0.30319
        Description: The process was terminated due to an unhandled exception.
        Exception Info: System.IO.FileNotFoundException
        ...
        at System.Windows.Window.OnClosing(System.ComponentModel.CancelEventArgs)
        at System.Windows.Window.WmClose()
        at System.Windows.Window.WindowFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
        at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
        at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
        at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
        at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
        at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
        at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
        at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

        I installed .NET 4.8 on the faulting machine and restarted before but it may not have done the job, how would one make sure that the application uses a later version of .NET?

      2. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (5)

        Michael Taylor 37,206Reputation points

        2023-01-05T16:42:59.257+00:00

        .NET 4.x is a single CLR install so if you installed .NET 4.8 then all .NET 4 apps on the machine are using that version now.

        The error indicates that a window was closing at the time of the failure. However none of your code is actually in the callstack. You mentioned that the PlatformSDK relied on Winforms but your app is WPF. Look at the docs for the SDK you're using. Ensure that the target machine has those same dependencies. What I'm thinking about here is the C++ runtime. If that SDK is managed only then you should be fine but I'm wondering if it relies on a native DLL that requires C++. Again, you need to go back to the documentation for the third party library and confirm what dependencies they list. Just looking at the assembly manifest isn't going to tell you all this.

      3. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (6)

        Arni Jonsson 1Reputation point

        2023-01-06T11:01:56.747+00:00

        Sorry, I cut a bit off of the call stack because it exceeded the character limit for the comment.
        The one line that I cut was:
        at ReglaPOS2.MainWindow.MainWindow_Closing(System.Object, System.ComponentModel.CancelEventArgs)
        which i replaced with the dots.

        The paymentSDK is being used when closing the application which explains the FnF there.

        The SDK's requirements is only .NET 4.6+, System requirements listed by Microsoft: https://learn.microsoft.com/en-us/dotnet/framework/get-started/system-requirements.
        It does not mention C++.

      4. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (7)

        Michael Taylor 37,206Reputation points

        2023-01-06T14:48:40.377+00:00

        Can you provide us more details on PaymentSDK. Who is the third party? Have you confirmed the version of the DLL that is causing issues is the same version that you are using locally and that is working on other machines. On a machine that is working, are there any files they have that the machine that isn't working doesn't have.

        It sounds like there are multiple machines having the issue and not just 1. Is there any similarity between these machines such as all being x64, all having .NET 4.8, all being on a single network, etc?

        Do you have an installer that installs your apps or do you copy-paste the binaries? If you copy-paste then please confirm that none of the binaries are blocked by Windows Explorer. You can do that by right clicking the files in Explorer and going to Properties. If Windows is blocking the file then you'll see a message.

        (Video) Crystal Report Error-Could not load file or assembly
      5. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (8)

        Arni Jonsson 1Reputation point

        2023-01-11T11:07:08.82+00:00

        It's a bit difficult since it's not a public SDK. I have sent an inquiry about the issue to the third party and they are looking into it as well.

        The DLL is tested on my device prior to release so it is the same DLL, besides I have the same version running on other computers that works.

        There have been a few machines that ran into this error, yes. I have had access to two of them but I haven't really found any suspicious similarities.

        1. The computers are managed probably with active directory by an organization. Not all of the faulting computers are managed like that though.
        2. They are running windows 10 but not same versions, one w10 Pro and the other w10 Enterprise LTSC.
        3. They both have .NET 4.8 installed.
        4. They are both x64-based
        5. They are both Toshibas 🤷

        I have contacted an admin at one of these organizations who will take a look if they notice anything unusual, the file being blocked etc.

        I use OneClick to install the app, no copy paste is being done.

        I double checked the appdata folder yesterday in one of the faulting computers and checked the properties of the SDK and there was no sign of any blocking there.

        Could it be that I am referencing the SDK incorrectly?

        The SDK is kept in the project under a folder called 3rdPartyPackages and then referenced from there.

        Winforms and System.Drawing is referenced from "Program Files(x86)".

        Do you know any way to see the path that the application uses to try to fetch the SDK or dependencies?

      6. WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (9)

        Michael Taylor 37,206Reputation points

        2023-01-11T15:41:34.17+00:00

        (Video) How To Fix Cefsharp.Core.Runtime.dll Error - Could Not Load File or Assembly

        .NET assemblies are pulled from the GAC so you would have added them to your project via Add References and then in the GAC. This SDK you would have had to reference by going to Add References and then browsing to the binary. It seems unlikely that you got this wrong.

        I'm still of the mindset there is a problem with the machine configuration but there is insufficient information to debug. Normally this kind of issue can be diagnosed by running fuslogvw to get the loading log. But that is only for admins and it is only available in VS. I don't know that you can run it on a standalone machine, I've never tried.

        Maybe the next step is to add detailed logging to your clean up code. Wrap the call to the SDK binary in a try-catch and log the exception details including the message, stack trace and any inner exceptions. This will help diagnose the issue. Most likely the FNF is being triggered with a child exception that has more details. We need that information.

        Alternatively you could create a simple console app that calls the same SDK (with exception handling) and then drop the console app onto the machine having issues. Then run it to get the exception details.

      Sign in to comment

    2. answered 2023-01-05T03:21:33.41+00:00 by

      WPF .NET application breaks with error Could not load file or assembly '' or one of its dependencies - Microsoft Q&A (10)

      Hui Liu-MSFT 14,546Reputation points • Microsoft Employee

      Hi, @Arni Jonsson . Welcome Microsoft Q&A.
      As cooldadtx said, the cause of Exception code: 0xe0434352 may be .NET Framework, Platform Target or 3rd Party Conflict, etc. You could try to check whether the .NET Framework and Platform of the application are consistent or have no conflicts.

      On a 86-bit Windows operating system: Executables and DLL that are compiled with the Any CPU execute on the 32-bit CLR. On a 64-bit Windows operating system: A DLL compiled with the Any CPU executes on the same CLR as the process into which it's loaded. Executables that are compiled with the Any CPU execute on the 64-bit CLR. The Target Platform of the program and the referenced DLL should be consistent at runtime. Generally speaking, we can set the Target Platform of the program to be consistent with the deployed operating system according to actual needs and the DLL is preferably Any CPU. The special deployment environment requires special consideration.

      It may also be that the installed application is corrupted, you can try to reinstall the problematic application.

      ----------------------------------------------------------------------------

      If the response is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

      0No comments

        Sign in to comment

      Sign in to answer

      Activity

      Sign in to follow questions and users

      Videos

      1. [SOLVED] Are you missing a using directive or an assembly reference Visual Studio
      (Firebitlab)
      2. C#/WPF - Deploying WPF apps with Squirrel
      (Kevin Bost)
      3. C# beginners :- Assembly , EXE and DLL
      (.NET Interview Preparation videos)
      4. Errors Loading Projects in Visual Studio
      (Randal Root)
      5. Adding AppSettings to WPF Core - A TimCo Retail Manager Video
      (IAmTimCorey)
      6. Converting an Existing WPF Application to .NET Core 3
      (Brian Lagunas)
      Top Articles
      Latest Posts
      Article information

      Author: Edwin Metz

      Last Updated: 12/11/2022

      Views: 6178

      Rating: 4.8 / 5 (78 voted)

      Reviews: 93% of readers found this page helpful

      Author information

      Name: Edwin Metz

      Birthday: 1997-04-16

      Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

      Phone: +639107620957

      Job: Corporate Banking Technician

      Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

      Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.