FileNotFoundException (Could not load file or assembly) thrown when using a .NET standard library in a full trust win32 component of UWP app


I'm having my domain logic in a .NET standard library. I'm trying to use it in a full trust win forms tray component defined in an UWP application. My domain logic library is referenced in both the UWP project and the win forms project. Now if I start the win forms app as full trust process in system tray and call the domain logic it throws a FileNotFoundException saying it cannot find the nuget packages added in my 'domain logic' library. However if I start the forms app separately, it gets executed properly. As per the answer, I have added copy task in post build event and the copied dlls are included in the project as well.

Here's a sample repo to reproduce the mentioned problem. The readme file contains brief explanation to reproduce the issue. How to fix the FileNotFound being thrown?

Here's the exception trace.

System.TypeInitializationException: The type initializer for 'DIServiceProviderSingleton' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at DomainLogic.DIServiceProvider..ctor()
   at DomainLogic.DIServiceProvider.DIServiceProviderSingleton..cctor()
   --- End of inner exception stack trace ---
   at DomainLogic.DIServiceProvider.get_Instance()
   at SystrayComponent.SystrayApplicationContext.PerformDomainLogic(Object sender, EventArgs e)

Initially the nuget package dlls were not copied to the bin folder of SystrayComponent. I fixed it by following the workaround posted here. Even after that I'm getting the mentioned exception.

Since debugger cannot be attached to the win32 counterpart, I've logged any exception thrown in app sandbox localstate file C:\Users\YourUserName\AppData\Local\Packages\UWPwithSystrayextension_brppa21vfw7f4\LocalState\Log.txt

asked on Stack Overflow Apr 6, 2020 by Razor • edited Apr 7, 2020 by Razor

1 Answer


In addition to including the exe file, you also need to include the DomainLogic.dll file.

Please find the DomainLogic.dll file in UWP-Systray-master\SystrayComponent\bin\Debug and add it to the Win32 folder.

After adding, "Include in the project" in Visual Studio.


User contributions licensed under CC BY-SA 3.0