dotnet / dotnet/core

"Could not load file or assembly" exception randomly when executing code on docker linux container from bamboo CI

Open
#4,921 14 comments 3 reactions 0 assignees View on GitHub
Dominant language
PowerShell
Stars
22k
Forks
4.9k
Avg merge
5d 5h
Merged PRs (30d)
29

Description

# Exceptions "Could not load file or assembly 'SomeAssemblyName, Version=VersionNumber, Culture=neutral, PublicKeyToken=SomeToken'. The system cannot find the file specified." are thrown randomly **(nondeterministic)** when executing code using "dotnet test" for some of the assembles.

Project is based on .NET Core 3.1, currently 3.1.201, but issue is reproducible on 3.1.300 as well. Project contains nunit-based automated tests. Issue occurs when executing code on docker linux containers in continuous environment based on Bamboo. Assemblies that appear in exceptions are the ones loaded from NuGet packages. Sample exceptions:

- Could not load file or assembly 'KellermanSoftware.Compare-NET-Objects, Version=4.65.0.0, Culture=neutral, PublicKeyToken=d970ace04cc85217'. The system cannot find the file specified.
- Could not load file or assembly 'Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106'. The system cannot find the file specified.

With **this same container, this same code, this same environment** you can make a number of runs and some of them will work well, some of them with throw exception regarding assembly A, some of them regarding assembly B and so on. There is no pattern.

CI task that builds and runs tests is:
dotnet test /path/to/project.csproj --logger:"console;verbosity=detailed" --logger:"trx;LogFileName=TestResults.trx" --results-directory:"results/" --settings:"/path/to/settings/file" -- NUnit.Where="cat == SomeNunitCategory"

Docker container is based on Centos 7.5.

What was checked:
1. Every time when there is an exception thrown, "missing" file that dotnet is unable to find exists in output directory (bin/Debug in my case).
2. File has proper permissions, checked with ls -al in CI plan.
3. File is not corrupted, checked with md5sum in CI plan and sum is this same every time, hence binary this file is OK.
4. dotnet test command was executed with variables COREHOST_TRACE=1 COREHOST_TRACE_VERBOSITY=4 and in log files there is just an exception, no other errors related to assemblies dotnet cannot find.
5. Tried loading from code with Assembly.LoadFrom() and in case of failure it throws System.IO.FileNotFoundException with a path to file in message ... and this file indeed exists in this path.

Described **problem occurs only on docker linux Bamboo agents**, it's not reproducible in Windows, Linux (real/virtual), docker Linux running locally (same container image).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.