title: Azure DevOps pipeline unit tests with library dependency not working
body: <p>If a C# project with a unit tests that uses MS fakes and a 3rd party library  in <code>.dll</code> I'll refer to as X. In my unit test project the <code>.dll</code> is referenced locally and is packed in the Azure GIT. Now when building the solution via an Azure DevOps pipeline using a MS hosted agent everything works fine, but the units tests keep failing at every test.</p>
  
  <p>The unit test yaml looks as follows:</p>
  
  <pre><code>- task: VSTest@2
    inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2: |
        **\*UnitTests*.dll
        !**\*TestAdapter.dll
        !**\obj\**
      searchFolder: '$(System.DefaultWorkingDirectory)'
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>System.IO.FileNotFoundException : Could not load file or assembly 'Y, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.</p>
  </blockquote>
  
  <p>Y is another <code>.dll</code> which I assume the first library depends on, although using <code>dumpbin /dependents X.dll</code> doesn't show it. I've tried adding Y to the project as reference yielding the same result. I've tried using the following Powershell script to add it:</p>
  
  <pre><code>- task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |
        $dllpath = 'dll'
        $files = Get-ChildItem -Path $dllpath -Name
        [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
        $publish = New-Object System.EnterpriseServices.Internal.Publish
        Foreach ($file in $files)
        {
          $publish.GacInstall($dllpath + "\" + $file)
        }
  </code></pre>
  
  <p>which changes the errors as follows:</p>
  
  <blockquote>
    <p>System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).</p>
  </blockquote>
  
  <p>I've checked online for the error, but couldn't find any solution to solve the issue.</p>
  
  <p>Anybody have any idea's how I can get the unit tests working on the MS Agent?</p>
  
  <p><a href="https://i.stack.imgur.com/uvDsB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uvDsB.png" alt="Configuration Manager"></a></p>