Search code examples
mstestvisual-studio-2019

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.


Solution

  • 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