cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.92k stars 730 forks source link

Assembly with same name is already loaded #2493

Open kentcb opened 5 years ago

kentcb commented 5 years ago

What You Are Seeing?

I'm attempting to switch from manually loading a slew of NuGets, to loading only the "main" ones and using loaddependencies to get the rest.

First of all, attempting to run my script is incredibly slow (even a second time once the cache is primed). Secondly, it gives me an error:

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

What is Expected?

That it works or gives me a more useful error.

What version of Cake are you using?

I tried with both 0.28.1 and 0.32.1.

Are you running on a 32 or 64 bit system?

64-bit

What environment are you running on? Windows? Linux? Mac?

Windows, but running the build inside a Linux Docker container.

How Did You Get This To Happen? (Steps to Reproduce)

Just running this puppy:

#addin nuget:?package=Cake.Git&version=0.19.0
#addin nuget:?package=Newtonsoft.Json&version=11.0.2

#addin nuget:?package=Microsoft.Azure.KeyVault&version=3.0.2&loaddependencies=true
#addin nuget:?package=Microsoft.Azure.Management.Fluent&version=1.18.0&loaddependencies=true
#addin nuget:?package=Microsoft.Rest.ClientRuntime.Azure&version=3.3.18&loaddependencies=true
#addin nuget:?package=Microsoft.Rest.ClientRuntime.Azure.Authentication&version=2.3.6&loaddependencies=true
#addin nuget:?package=Microsoft.ServiceFabric.Client.Http&version=2.0.0-preview1&loaddependencies=true
#addin nuget:?package=WindowsAzure.Storage&version=9.3.3&loaddependencies=true

Task("Build")
    .Does(() => Console.WriteLine("Oh, hai"));

RunTarget(Argument("target", "Build"));

Output Log

I've upload the full diagnostic log here.

aFuerst commented 5 years ago

I am getting this same error with just a single nuget dependency

#addin "nuget:?package=ServiceStack&version=5.0.2&loaddependencies=true"

Task("Build")
    .Does(() => Console.WriteLine("Oh, hai"));

RunTarget(Argument("target", "Build"));

System.Net.Http.WinHttpHandler shows up twice as being referenced by ServiceStack

The addin ServiceStack will reference System.Net.Http.WinHttpHandler.dll.
The addin ServiceStack will reference System.Net.Http.WinHttpHandler.dll.

I can reproduce this on both Cake version 0.30.0 and 0.32.1

DTTerastar commented 5 years ago

I get this error on the dncore version of cake pretty much any time I try and have &loaddependencies=true on more than one addin. Full framework doesn't get it ever.