0

When running a tests from a test plan in Azure Pipeline using Automated tests using Release stage, we are getting a failure "Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. The system cannot find the file specified."

As this is a 64 bit dll, we have provided /Platform:x64 option in Vstest task. Below is the yaml for the VsTest task in the release pipeline:

steps:
- task: VSTest@2
  displayName: 'VsTest - Test Run on Demand for ETL Tests'
  inputs:
    testSelector: testRun
    searchFolder: '$(System.DefaultWorkingDirectory)\_Development\bin\Release'
    vsTestVersion: toolsInstaller
    pathtoCustomTestAdapters: '$(System.DefaultWorkingDirectory)\_Development\packages\'
    runTestsInIsolation: false
    otherConsoleOptions: '/Platform:x64'
    platform: x64
    configuration: Release
  continueOnError: true

We are getting the same error even if the tests are run in isolation.

The Reflection LoaderExceptions fusion log is as follows:

Reflection error message is: Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. The system cannot find the file specified.
Fusion Log:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\AzAgent\A1\_work\_tool\VsTest\16.7.1\x64\tools\net451\Common7\IDE\Extensions\TestPlatform\testhost.x86.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23
 (Fully-specified)
LOG: Appbase = file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common
LOG: Initial PrivatePath = NULL
Calling assembly : <calling assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\AzAgent\A1\_work\r1\a\_Development\bin\Release\<test dll>.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/packages/MSTest.TestAdapter.1.4.0/build/_common/sapnco/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco/sapnco.DLL.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco.EXE.
LOG: Attempting download of new URL file:///C:/AzAgent/A1/_work/r1/a/_Development/bin/Release/sapnco/sapnco.EXE.

The dll is present in the locations from which a download attempt is made in the fusion log.

We are not sure how to fix this error. We changed the build platform from Any CPU to x64 too. What is the solution to the issue?

Ashwin Hariharan
  • 204
  • 2
  • 12
  • Did you restore packages before running tests? – Krzysztof Madej Oct 23 '20 at 14:46
  • @KrzysztofMadej The packages are present in the _Development\packages folder and that folder is specified in the custom adapters path. This package is not present in the packages.config file and hence not being restored by nuget. It is a reference to the package path. – Ashwin Hariharan Oct 27 '20 at 05:06

1 Answers1

0

Could not load file or assembly sapnco vstest Azure Pipelines

Since you are running tests from Release stage, you should make sure the assembly file sapnco.dll is in your build artifact, so that could be downloaded to the release pipeline.

You could check the folder C:/AzAgent/A1/_work/r1/a/_Development/bin/Release for assembly file sapnco.dll.

If that dll file is not there, you need to copy and publish it as artifact.

Another point is that make sure you are using the package sapnco3.x64 instead of sapnco, which is used for x64.

Update:

After I double-checked your test task, I found that your select tests using is Test run rather than Test assemblies, the test run:

Use this option when you are setting up an environment to run tests from the Test hub. This option should not be used when running tests in a continuous integration / continuous deployment (CI/CD) pipeline.

enter image description here

To resolve this issue, please try to use Test assemblies.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • the sapnco.dll package is present in the C:/AzAgent/A1/_work/r1/a/_Development/bin/Release folder. There is a copy step which copies the 64 bit sapnco dll from the packages folder to the specified path. – Ashwin Hariharan Oct 27 '20 at 05:08
  • @AshwinHariharan, How did you add the `sapnco.dll`, directly add the dll file to the project or by nuget package? Would you please share the project file about the party of reference of `sapnco.dll` and share the build and release pipeline configuration. – Leo Liu Oct 27 '20 at 09:02
  • This is the package used in nuget packages.config file. On build, during nuget restore, it gets restored to the packages folder. – Ashwin Hariharan Oct 27 '20 at 09:45
  • `task: VSBuild@1 inputs: solution: vsVersion: '16.0' msbuildArgs: '$(msbuildFlags) /t:Rebuild /p:DeployOnBuild=true /p:CreatePackageOnPublish=True /p:ExcludeGeneratedDebugSymbol=true /p:PackageLocation="$(OutputDirtry)"' platform: 'Any CPU' configuration: Release clean: true restoreNugetPackages: true displayName: 'Build SCH'` This is the CI build configuration. We have tried changing Any CPU to x64 too – Ashwin Hariharan Oct 27 '20 at 09:46
  • Release configuration is specified in the post – Ashwin Hariharan Oct 27 '20 at 09:47
  • Prior to build we download and extract the artifacts. Test Platform installer: `steps: - task: VisualStudioTestPlatformInstaller@1 displayName: 'Visual Studio Test Platform Installer' inputs: versionSelector: latestStable continueOnError: true condition: always()` – Ashwin Hariharan Oct 27 '20 at 09:50
  • File extraction step: `steps: - task: ExtractFiles@1 displayName: 'Extract files ' inputs: archiveFilePatterns: '$(System.DefaultWorkingDirectory)\_Development\**\*.zip' destinationFolder: '$(System.DefaultWorkingDirectory)\_Development' cleanDestinationFolder: false overwriteExistingFiles: true` – Ashwin Hariharan Oct 27 '20 at 09:51
  • @AshwinHariharan, Thanks for your reply. I have updated my answer, please check if it helps you. – Leo Liu Oct 28 '20 at 06:54
  • So even if I run tests from the test plan, using a release stage, I should use test assembly instead of test run right? – Ashwin Hariharan Oct 28 '20 at 11:21
  • @AshwinHariharan, That because you set the test task in the release pipeline rather than build pipeline, it could not get the assembly. If you want to use Test Run, please add test task in your build pipeline. – Leo Liu Oct 29 '20 at 07:22
  • Sure Leo. We shall try this out. Thanks for your help – Ashwin Hariharan Oct 29 '20 at 11:47
  • @AshwinHariharan: Did this help? – Rohit Jan 25 '21 at 23:32