Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load file or assembly 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies #27533

Closed
sandersaares opened this issue Oct 4, 2018 · 12 comments

Comments

@sandersaares
Copy link

  1. Create a new .NET Framework 4.7.1 console app project.
  2. Install BenchmarkDotNet NuGet package.
  3. Observe that above resulted in <package id="System.ValueTuple" version="4.3.0" targetFramework="net471" /> in packages.config due to some dependency.
  4. Paste the following code into Program.cs and excute the app.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            BenchmarkRunner.Run<Foo>();
        }
    }

    [ClrJob]
    public class Foo
    {
        [Benchmark]
        public void Bar()
        {

        }
    }
}

Expected result: app executes and performs some no-op benchmarks.

Actual result:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   --- End of inner exception stack trace ---
   at BenchmarkDotNet.Running.BenchmarkConverter.GetParameterDefinitions(Type type)
   at BenchmarkDotNet.Running.BenchmarkConverter.MethodsToBenchmarksWithFullConfig(Type containingType, MethodInfo[] benchmarkMethods, ReadOnlyConfig fullConfig)
   at BenchmarkDotNet.Running.BenchmarkConverter.TypeToBenchmarks(Type type, IConfig config)
   at BenchmarkDotNet.Running.BenchmarkRunner.Run[T](IConfig config)
   at ConsoleApp3.Program.Main(String[] args) in C:\Source\ConsoleApp3\ConsoleApp3\Program.cs:line 15

I see the following automatically added to my app.config:

      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
      </dependentAssembly>

I do not see ValueTuple in my bin directory.

@sandersaares
Copy link
Author

If I upgrade NuGet packages to recent versions, it looks like the error goes away. Does this mean that 4.3.0 is not actually compatible with net471, despite getting installed? Does it mean the BenchmarkDotNet package owner should require a later one to work around this? What is the right way forward here, so installing the package will result in a successful runtime experience?

@karelz
Copy link
Member

karelz commented Oct 5, 2018

@joperezr is it a known issue?

@ViktorHofer
Copy link
Member

cc @adamsitnik

@joperezr
Copy link
Member

joperezr commented Oct 8, 2018

@sandersaares which version of VS are you using? do you mind sharing a msbuild.binlog of your build when the problem repros? In order to do this, run msbuild yourProject.csproj /t:rebuild /bl on a developer command prompt.

@joperezr is it a known issue?

This one is interesting as System.ValueTuple isn't one of the assemblies that we inject facades for when targeting 4.7.1. This looks a lot like the problem we fixed on 4.7.1 patch for ValueTuple where the unification table was wrong, but I don't think that this is the problem we are seeing here, since a binidng redirect was added, which seems to be the cause of the problem. the binlog should help understand why was that binding redirect generated.

@sandersaares
Copy link
Author

I am using VS 15.8.6.

binlog.zip

@GSPP
Copy link

GSPP commented Oct 9, 2018

@joperezr
Copy link
Member

Oh I see, this is a known issue with packages.config. What I think is going on here is that when you add one of your nuget package dependnecies, then the NuGet package manager is adding the binding redirect into your app.config. This is a bug since the NuGet package manager should never be emitting binding redirects as it doesn't have the full picture of all your references.

Can you try the exact same steps, but instead of adding the package depenendencies with VS, add them using <PackageReference ? Basically add the package reference by adding to your project the following:

<ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.11.1" />
</ItemGroup>

I would expect that doing that should get rid of the error.

@sandersaares
Copy link
Author

I confirm that adding a PackageReference successfully works around this defect.

Can you post a link to the mentioned NuGet issue report that I could watch?

@pavel-agarkov
Copy link

I had to manually put System.ValueTuple.dll into

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ValueTuple\v4.0_0.0.0.0__cc7b13ffcd2ddd51

in order for it to be automatically found in .Net 4.6.1 console app. No other recommendations helped.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@ViktorHofer ViktorHofer removed the untriaged New issue has not been triaged by the area owner label Jul 8, 2020
@mayawarrier
Copy link

@pavel-agarkov Thanks, this is the only solution that worked.

I got the same error message with System.ValueTuple version 4.0.3.0. We're targeting .NET 4.7.2.

@chucklu
Copy link

chucklu commented Nov 13, 2020

I encounter this issue, and seems like the vs problem, and the nuget add the bindingRedirect automatically for me which make the build pass.
https://stackoverflow.com/questions/52859229/visual-studio-conflicts-between-reference-and-platform

Encountered conflict between 'Reference:System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL' and 'Platform:System.ValueTuple.dll'. Choosing 'Reference:System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL' because AssemblyVersion '4.0.3.0' is greater than '4.0.2.0'.

@sandersaares
Copy link
Author

I have not encountered this in forever, so closing.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants