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

dotnet publish with test project leads to "Could not load file or assembly 'Microsoft.Extensions.FileSystemGlobbing, Version=3.1.0.0" #1106

Closed
timmkrause opened this issue Mar 4, 2021 · 3 comments · Fixed by #1243
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@timmkrause
Copy link

timmkrause commented Mar 4, 2021

Trying to publish a test project and execute tests within Azure Pipelines (at the bottom you can find dotnet --info).

Getting the following, when trying to run the tests:

System.TypeInitializationException: The type initializer for 'Foo.Bar' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Bar.Baz' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.FileSystemGlobbing, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Stack Trace:
    at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.ChangeTokenInfo..ctor
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.ChangeTokenInfo..ctor(CancellationTokenSource tokenSource, CancellationChangeToken changeToken)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.GetOrAddFilePathChangeToken(String filePath)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.GetOrAddChangeToken(String pattern)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0()
   at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1..ctor(Func`1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider..ctor(JsonConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()

The problem is, that a wrong version of Microsoft.Extensions.FileSystemGlobbing.dll is part of the artifact (2.0.1.18051 and product version 2.0.1-rtm-10011).
It took me some hours to reproduce it and find out what is actually causing the problem.
Finally I tried to start from scratch and aligned the project in baby steps to the project which is causing the problem.

Repro steps (.NET Core 3.1 or .NET 5 does not seem to make a difference):

dotnet new mstest

Observe coverlet.collector version 1.3.0 is installed.

dotnet publish --output out-tests

Observe Microsoft.Extensions.FileSystemGlobbing.dll file version 2.0.1.18051 and product version 2.0.1-rtm-10011 in the output folder.

dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.Json

dotnet publish --output out-tests

Observe Microsoft.Extensions.FileSystemGlobbing.dll file version 3.100.1221.6909 and product version 1.1.12+4210e7... in the output folder.

dotnet add package coverlet.collector --version 3.0.3

Update coverlet.collector to version 3.0.3 and observe Microsoft.Extensions.FileSystemGlobbing.dll file version 2.0.1.18051 and product version 2.0.1-rtm-10011 which is not the correct version anymore.

Quickly analyzing the NuGet package did not led to anything beside noticing, that it only targets netstandard1.0.
Nothing seems to have changed from 1.3.0 to 3.0.3 regarding that DLL, no scripts, nothing. I don't get what is going on.
Downgrading coverlet.collector for now.

It seems to me though that publish breaks it somehow, dotnet build always produces the correct version in bin\Debug.

❯ dotnet --info:

.NET SDK (gemäß "global.json"):
 Version:   5.0.200
 Commit:    70b3e65d53

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.200\

Host (useful for support):
  Version: 5.0.3
  Commit:  c636bbdc8a

.NET SDKs installed:
  3.1.301 [C:\Program Files\dotnet\sdk]
  5.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
@Osypchuk
Copy link

Faced a similar issue with Newtonshoft.json and coverlet.collector 3.0.3.

Project file code:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Run '''dotnet publish''' and lookup version of NewtonSoft json in output folder.
The actual result would be 9.0.1 (corresponds to the minimal requirement for Microsoft.NET.Test.Sdk)
Expected result: 12.0.2

Workaround:
Downgrade to 1.3.0 fixes the issue.

@MarcoRossignoli MarcoRossignoli added duplicate This issue or pull request already exists and removed untriaged To be investigated labels Oct 8, 2021
@MarcoRossignoli
Copy link
Collaborator

dup of #1226

@MarcoRossignoli
Copy link
Collaborator

Hi all!

Can someone dogfood this preview version with the fix attempt and tell me if it works?
https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json version 3.1.1-preview.10

@MarcoRossignoli MarcoRossignoli added the bug Something isn't working label Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
4 participants