Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest DeploymentItem attribute causes SQLite.Interop.dll not found

The suite of unit tests I have immediately fails the test run with System.DllNotFoundException: Unable to load DLL 'SQLite.Interop.dll' which is a dependency required within the test [AssemblyInitialize] methods.

I've determined this is caused by executing any test that is using the [DeploymentItem] attribute and is the case for either a class or method. Any tests that do not use this attribute pass.

With Test Diagnostic logging enabled in VS2019 there are no obvious errors but I can see this config.

<RunSettings>
  <RunConfiguration>
    <ResultsDirectory>D:\Dev\****\src\TestResults</ResultsDirectory>
    <SolutionDirectory>D:\Dev\****\src\</SolutionDirectory>
    <TargetPlatform>X86</TargetPlatform>
    <CollectSourceInformation>False</CollectSourceInformation>
  </RunConfiguration>
</RunSettings>

My test projects are all configured for <PlatformTarget>AnyCPU</PlatformTarget> so I wonder if the SQLite.Interop.dll is not found because of an issue with x86 vs x64.

  • Where can I configure the <RunSettings>?
  • Why would SQLite.Interop.dll not be found?

UPDATE

Using procmon.exe filtering for testhost.exe and SQLite.Interop.dll I can see that a test without [DeploymentItem] attributes starts looking for the dll in the project bin\Debug folder which finds it at bin\Debug\x64\SQLite.Interop.dll.

Those tests with the attribute starts looking in the Test Results directory TestResults\...\Out then all across the machine C:\Windows, C:\Program Files, C:Users but never further under bin\Debug.

Running the same tests using VSTest.Console.exe does not have this issue.

  • How can I apply System.Data.SQLite from NuGet, interop dll not copied to output directory to the .\Out directory for the unit tests?
like image 370
Dave Anderson Avatar asked Apr 09 '26 15:04

Dave Anderson


1 Answers

To resolve;

  1. Configure unit tests by using a .runsettings file
  2. Add setting <DisableAppDomain>True</DisableAppDomain>, see Configure a test run

Note that run settings cannot be retained at the project or solution level and need to be set in the IDE; https://developercommunity.visualstudio.com/content/problem/151608/ability-to-set-runsettings-in-project-file.html

like image 145
Dave Anderson Avatar answered Apr 12 '26 19:04

Dave Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!