Skip to content

[Bug]: Run-TestsInBcContainer ends with error "Unable to load one or more of the requested types" #4062

@kine

Description

@kine

BCContainerhelper version

6.1.11-preview1369

Describe the issue

When using artifacts which have library Microsoft.Internal.AntiSSRF.dll of version 2.2. (new Sandbox artifacts), the Add-Type command for this dll fails with error:

Unable to load one or more of the requested types...

It is because this dll is in version 2.2. depending on System.Threading.Tasks.Extensions.dll which is not correctly resolved, even when it is placed in same folder.

Command or script used to produce the issue

Create container:

$containerName = 'test'
$artifactUrl = 'https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/27.1.41698.42561/cz'
New-BcContainer `
    -accept_eula `
    -containerName $containerName `
    -artifactUrl $artifactUrl `
    -authenticationEMail '[email protected]' `
    -updateHost -includeTestToolkit -includeTestLibrariesOnly

Run the tests:

 Run-TestsInBcContainer `
                 -containerName test `
                 -tenant default `
                 -credential $credentials `
                 -testSuite 'DEFAULT' `
                 -XUnitResultFileName 'result.xml' `
                 -AzureDevOps 'error' `
                 -detailed:$true `
                 -restartContainerAndRetry:$false `
                 -extensionId '12345678-1234-1234-1234-1234567890' `
                 -companyName "XXX" `
                 -returnTrueIfAllPassed:$true -verbose

Full output of the command or script

Using Container
WARNING: TaskScheduler is running in the container, this can lead to test failures. Specify -EnableTaskScheduler:$false to disable Task Scheduler.
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Exception Script Stack Trace:
at <ScriptBlock>, C:\ProgramData\BcContainerHelper\Extensions\BCAppsdkr-agent3\PsTestTool\PsTestFunctions.ps1: line 14
at <ScriptBlock>, <No file>: line 50

PowerShell Call Stack:
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.1.11\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 74
at Run-TestsInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.1.11\AppHandling\Run-TestsInNavContainer.ps1: line 451
at Run-ALTestInContainer, C:\Program Files\WindowsPowerShell\Modules\NVRAppDevOps\2.8.6\Run-ALTestInContainer.ps1: line 92
at <ScriptBlock>, C:\_work\dkr-agent3\_tasks\runbctestincontainer_047393e1-82e4-4d24-8275-237409bb378c\2.7.0\runtestsdockerTask.ps1: line 32
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, <No file>: line 22
at <ScriptBlock>, <No file>: line 18
at <ScriptBlock>, <No file>: line 1

This output is when the test is started from another container on same host (containerized Azure DevOps Agent). It will be slightly different for running the tests directly from the host.

Additional information

Problem are new artifacts having v2.2. of the Microsoft.Internal.AntiSSRF.dll. Solution is to add resolver into PsTestFunctions.ps1:

if (Test-Path $antiSSRFdll) {
    $Threading = [Reflection.Assembly]::LoadFile((Join-Path ([System.IO.Path]::GetDirectoryName($clientDllPath)) 'System.Threading.Tasks.Extensions.dll'))
    $onAssemblyResolve = [System.ResolveEventHandler] {
        param($sender, $e)
        if ($e.Name -like "System.Threading.Tasks.Extensions, Version=*, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51") {
            return $Threading
        }
        return $null
    }
    [System.AppDomain]::CurrentDomain.add_AssemblyResolve($onAssemblyResolve)
    try {
        Add-Type -Path $antiSSRFdll
    }
    finally {
        [System.AppDomain]::CurrentDomain.remove_AssemblyResolve($onAssemblyResolve)
    }
}

Does this happen every time?

Yes

Did this used to work?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions