cake: System.Data.SqlClient in Cake.CoreCLR Assembly Load Error
What You Are Seeing?
When referencing System.Data.SqlClient in my Cake file, I get the following exception when run from the global tool in a Docker container:
Assembly with same name is already loaded
When running from Windows (build.ps1), the reference isn’t needed, and even when present, causes no issues.
I asked for assistance in the chat, and was directed here.
What is Expected?
The Cake script should compile.
What version of Cake are you using?
dotnet core global tool 0.30.0
Are you running on a 32 or 64 bit system?
64-bit
What environment are you running on? Windows? Linux? Mac?
Docker (Linux on Windows) microsoft/dotnet:2.1.400-sdk-stretch
Are you running on a CI Server? If so, which one?
No
How Did You Get This To Happen? (Steps to Reproduce)
In my build.cake file:
#addin "nuget:?package=System.Data.SqlClient&version=4.5.0"
#addin "nuget:?package=Cake.Docker&version=0.9.6"
#addin "nuget:?package=dbup-core&version=4.1.0"
#addin "nuget:?package=dbup-sqlserver&version=4.1.0"
In my Docker file:
FROM microsoft/dotnet:2.1.400-sdk-stretch AS build-env
WORKDIR /app
COPY ./ ./
ENV PATH="/root/.dotnet/tools:${PATH}"
RUN dotnet tool install -g Cake.Tool --version 0.30.0
RUN dotnet cake build.cake
Output Log
root@dc8cbcdce3b2:/app# dotnet cake build.cake -v=Diagnostic
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing /app/build.cake...
Processing build script...
Installing tools...
Retrieving package 'ReportGenerator 4.0.0-rc4' from '/root/.nuget/packages/'.
Package ReportGenerator.4.0.0-rc4 has already been installed.
Successfully installed 'ReportGenerator 4.0.0-rc4' to /app/tools
Executing nuget actions took 68.73 ms
Installing addins...
Found package 'System.Data.SqlClient 4.5.0' in '/app/tools/Addins'.
Package System.Data.SqlClient.4.5.0 has already been installed.
Successfully installed 'System.Data.SqlClient 4.5.0' to /app/tools/Addins
Executing nuget actions took 2.18 ms
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
The addin System.Data.SqlClient will reference System.Data.SqlClient.dll.
Found package 'Cake.Docker 0.9.6' in '/app/tools/Addins'.
Package Cake.Docker.0.9.6 has already been installed.
Successfully installed 'Cake.Docker 0.9.6' to /app/tools/Addins
Executing nuget actions took 0.46 ms
The addin Cake.Docker will reference Cake.Docker.dll.
Found package 'dbup-core 4.1.0' in '/app/tools/Addins'.
Package dbup-core.4.1.0 has already been installed.
Successfully installed 'dbup-core 4.1.0' to /app/tools/Addins
Executing nuget actions took 0.65 ms
The addin dbup-core will reference dbup-core.dll.
Found package 'dbup-sqlserver 4.1.0' in '/app/tools/Addins'.
Package dbup-sqlserver.4.1.0 has already been installed.
Successfully installed 'dbup-sqlserver 4.1.0' to /app/tools/Addins
Executing nuget actions took 0.57 ms
The addin dbup-sqlserver will reference dbup-sqlserver.dll.
Verifying assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Error: System.IO.FileLoadException: Assembly with same name is already loaded
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Cake.Core.Reflection.AssemblyLoader.Load(FilePath path, Boolean verify) in C:\projects\cake\src\Cake.Core\Reflection\AssemblyLoader.cs:line 31
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 171
at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 73
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (21 by maintainers)
Commits related to this issue
- (GH-2275) Exclude runtime assemblies from resolver - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Exclude runtime assemblies from resolver - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Exclude runtime assemblies from resolver - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Correctly reference runtime libraries from addins - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- Merge branch 'develop' into feature/GH-2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- Merge branch 'develop' into feature/GH-2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Correctly reference runtime libraries from addins - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Correctly reference runtime libraries from addins - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Correctly reference runtime libraries from addins - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- (GH-2275) Correctly reference runtime libraries from addins - Fixes #2275 — committed to bjorkstromm/cake by bjorkstromm 5 years ago
- Merge branch 'mholo65-feature/GH-2275' into develop * mholo65-feature/GH-2275: Update NuGet Client libs and Platform abstractions (GH-2275) Correctly reference runtime libraries from addins — committed to cake-build/cake by devlead 5 years ago
@IvorBright, this have not bern fixed yet. If my previous investigations are still valid, then:
Should be a quick fix we could look into for 0.31.0.
Very few addins without monikers https://github.com/cake-contrib/Home/blob/master/Audit_for_Cake_0.28.0.md and my guess is that those won’t work with 0.28.0+ of Cake anyways.
We can also use that to retrieve Framework Assemblies as well.
Investigated. It’s related to how we resolve lib items in NuGetContentResolver. It loaded when I removed the
runtimesfolder from the extracted NuPkgWe should either:
runtimesfolder in content resolver, orPackageFolderReaderto get lib items, as described in my blog here