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

Running dotnet test on projects that reference Newtonsoft.Json < 9.0.0.0 throws exception #613

Closed
pwiens opened this issue Mar 14, 2017 · 4 comments

Comments

@pwiens
Copy link

pwiens commented Mar 14, 2017

Description

Running dotnet test on projects that reference Newtonsoft.Json < 9.0.0.0 causes test to throw exception.

Steps to reproduce

Create a library project targetting .NET 4.5:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net45</TargetFramework>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="6.0.5" />
  </ItemGroup>
</Project>

Create unit test project referencing the library project and mstest:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net45</TargetFramework>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MSTest.TestFramework" version="1.1.13" />
    <PackageReference Include="MSTest.TestAdapter" version="1.1.13" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="Library.csproj" />
  </ItemGroup>
</Project>

Execute dotnet test Library.Test.csproj

Expected behavior

Test run succeeds

Actual behavior

Test run fails with the following exception:
Error Message:

Test method Foo threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Environment

Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
.NET Command Line Tools (1.0.1)

Product Information:
Version: 1.0.1
Commit SHA-1 hash: 005db40cd1

Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.1

@pwiens
Copy link
Author

pwiens commented Mar 14, 2017

@livarcocc @piotrpMSFT

@codito
Copy link
Contributor

codito commented Mar 15, 2017

@Arkasha a PackageReference to Microsoft.NET.Test.Sdk is missing in test project. Can you please add it? It will allow nuget to compute dependencies closure/binding redirects appropriately.

You may hit into #428, this workaround will help #428 (comment)

@pwiens
Copy link
Author

pwiens commented Mar 16, 2017

I did that. It didn't fix the issue.

@Faizan2304
Copy link
Contributor

@Arkasha: I tried to repro it but no luck. Can you please share a repro project.

Can you also try this:
Add following line in your test project and run the test

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Faizan2304 added a commit to Faizan2304/vstest that referenced this issue Mar 21, 2017
1) microsoft#613
2) microsoft#428
3) microsoft#391
4) microsoft#595

Fix:
Generate config file for test project targeting .NET Framework. This config file has have binding redirect which is needed at time of running tests.
Faizan2304 pushed a commit to Faizan2304/vstest that referenced this issue Mar 27, 2017
1) microsoft#391
2) microsoft#613

Fix: Remove binding redirect of Newtonsoft.json from testhost config file
Faizan2304 added a commit that referenced this issue Apr 4, 2017
…663)

* Issues:
1) #391
2) #613

Fix: Remove binding redirect of Newtonsoft.json from testhost config file

* Address PR comment

* Addressing PR comment

* Fixed "path too long exception"

* fix Path too long warning

* fix build  issue

* Binding redirect Newtonsoft.json

* Adding assembly redirect for Newtonsoft.json in datacollector. We have to do this because the folder which contains datacollector has Newtonsoft.Json(9.0) and datacollect depends on 8.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants