1

Before this gets flagged as dupe - I did find this question and tried that and it didn't work

This is all happening in Test projects the methods in question are being called as they have the OneTimeSetup attribute - not sure if relevent but the more info the better right

Project A

References - System.Collections.Immutable v 1.3.33 - a dependency of using ScriptCs but also utilised directly in code cs proj has this entry

<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>......\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\System.Collections.Immutable.dll</HintPath>

<Private>True<<Private> </Reference>

Project A contains a Base Class

[SetUpFixture]
public abstract class BaseClass
{
    [OneTimeSetup]
    public void DoSomething()
    {
        var MyClass = new MyClass();
        MyClass.DoStuff();
        //etc etc
    }
}

it also contains the class MyClass - this class directly uses types from System.Collections.Immutable

public class MyClass
{
    private ImmutableDictionary<string,string> myImmutableDictionary = ImmutableDictionary.Create<string,string>();

    public void DoStuff()
    {
        //does things
    }
}

Project B - Has no direct reference to System.Immutable.Collections - Has project reference to Project A

In project B we have a class that inherits from BaseClass in project B

    [SetUpFixture]
    public class SubClass : BaseClass
    {
        [OneTimeSetup]
        public void SomeMethod()
        {
            DoSomething(); //Here it goes bang

        }
    }

So we were alerted to an issue where all our tests on the build server where failing for the same reason

Could not load file or assembly 'System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I ran this locally and got the same issue. I investiaged the output folder for Project B and to my surprise it did not contain 'System.Collections.Immutable.dll' - hence why it couldn't find it.

A collegue of mine ran them on their machine and the tests did run and we looked in their output folder of Project B and even more surprisingly there was a 'System.Collections.Immutable.dll' file there. HOWEVER... it was not the version that was found in Project A's output folder (1.1.33) it was 4.x.x - I'm thinking this came from the GAC but due to someother oddity we couldn't confirm if they had that dll in their GAC

So my mind was a bit blown

My understanding is the MSBuild takes the dll from the GAC as a last resort and the Hint path should be used first (Yes I checked the dll is present where the hint path is pointing too)

So..

  1. Why is the System.Collections.Immutable.dll not being copied from Project A's output folder into Project B?
  2. Where the hell is coming from on my collegeues machine?

I am using Visual Studio 2019 if that makes a difference

Dave
  • 2,829
  • 3
  • 17
  • 44
  • If you want to track down where the mystery file comes from on your colleague's machine, give http://msbuildlog.com/ a try. – Jimmy May 03 '19 at 07:11

2 Answers2

2

Since your projects (judging from the descriptions) are using packages.config, you need to explicitly install the NuGet packages you are using in Project A into Project B as well, since they don't flow transitively.

But: System.Collections.Immutable.dll should not be part of the ScriptCs package in the first place. This may be a packaging issue with ScriptCs.

Also: You may have trouble generating binding redirects in the test project. If so, try adding this xml to the test project file: (see Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0)

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
-1

Why is the System.Collections.Immutable.dll not being copied from Project A's output folder into Project B?

Maybe you use Build Depenencies=>Project Dependencies which caused this issue. Please Go Add=>Reference=>Projects=>Solution to add project reference.

enter image description here

Where the hell is coming from on my collegeues machine?

I've checked in vs2019, the dll version in projectB is corresponding to what is in projectA.(I've changed the System.Collections.Immutable package version from 1.4.0 to 1.6.0 by nuget package manager, their versions all match )

Community
  • 1
  • 1
LoLance
  • 25,666
  • 1
  • 39
  • 73