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

SpecFlow doesn't work with .NET Core 3.1.200 SDK #1912

Closed
12 of 33 tasks
SabotageAndi opened this issue Mar 17, 2020 · 51 comments · Fixed by #1971
Closed
12 of 33 tasks

SpecFlow doesn't work with .NET Core 3.1.200 SDK #1912

SabotageAndi opened this issue Mar 17, 2020 · 51 comments · Fixed by #1971
Labels
Bug Generator msbuild .NET Core Support SpecFlow Team Backlog this issue are in the backlog of the SpecFlow Team

Comments

@SabotageAndi
Copy link
Contributor

SabotageAndi commented Mar 17, 2020

SpecFlow Version:

  • 3.1
  • 3.0
  • 2.4
  • 2.3
  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number:

Project Format of the SpecFlow project

  • Classic project format using packages.config
  • Classic project format using <PackageReference> tags
  • Sdk-style project format

.feature.cs files are generated using

  • SpecFlow.Tools.MsBuild.Generation NuGet package
  • SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • VS 2019
  • VS 2017
  • VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • Enabled
  • Disabled

Are the latest Visual Studio updates installed?

  • Yes
  • No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Framework:

  • >= .NET 4.5
  • before .NET 4.5
  • .NET Core 2.0
  • .NET Core 2.1
  • .NET Core 2.2
  • .NET Core 3.0

Test Execution Method:

  • Visual Studio Test Explorer
  • TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • Command line – dotnet test

Issue Description

When using the .NET Core 3.1.200 SDK, the MSBuild Generation fails with following error:

C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error : [SpecFlow] System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified. [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error : File name: 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41' [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
t32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Attribute.GetCustomAttributes(Assembly element, Type attributeTC:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at TechTalk.SpecFlow.Generator.Plugins.GeneratorPluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.LoadPlugin(PluginDescriptor pluginDescriptor, IGeneratorPluginLoader pluginLoader, GeneratorPluginEvents generatorPluginEvents, UnitTestProviderConfiguration unitTestProviderConfigration) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.LoadPlugins(ObjectContainer container, GeneratorPluginEvents generatorPluginEvents, UnitTestProviderConfiguration unitTestProviderConfigration, IEnumerable`1 generatorPlugins) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings, IEnumerable`1 generatorPlugins) [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :    at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute() [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :  [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]
C:\Users\awi\.nuget\packages\specflow.tools.msbuild.generation\3.1.62\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error :  [C:\work\SpecFlow-Examples\NETCore Examples\BowlingKata-SpecFlowJson-xUnit\Bowling.SpecFlowXUnit\Bowling.SpecFlowXUnit.csproj]

Steps to Reproduce

Workaround

Set Environment variable to get all MSBuild behaviour:

MSBUILDSINGLELOADCONTEXT=1

@puco
Copy link

puco commented Mar 17, 2020

Having the same issue in Docker build. Was using mcr.microsoft.com/dotnet/core/sdk:3.1-alpine and switched to mcr.microsoft.com/dotnet/core/sdk:3.1.102-alpine. Noticed that 3.1.200 uses MSBuild 16.5, whereas 3.1.102 uses 16.4

@trondgod
Copy link

trondgod commented Mar 17, 2020

The SDK version 3.1.102 seems to be gone...
microsoft/azure-pipelines-tasks#12540

@SabotageAndi
Copy link
Contributor Author

SabotageAndi commented Mar 17, 2020

@trondgod They have it on their download page: https://dotnet.microsoft.com/download/dotnet-core/3.1
Looks like 3.1.102 was released with 3.1.200 and the difference is the supported VS version (which is also MSBuild version).

@dasMulli
Copy link

dasMulli commented Mar 18, 2020

MSBuild 16.5 has a new assembly loading approach for tasks that may have side effects. (which has been an ask for years, but it behaves a bit differently when loading dependencies)
You can try to set MSBUILDSINGLELOADCONTEXT=1 (env var) to get the old behavior.

@rainersigwald
Copy link

@SabotageAndi I suspect @dasMulli has correctly identified the reason this is happening. But I'm not sure exactly what the problem is. Is there an easy way to get a small repro project so that I can debug the assembly loading behavior?

@SabotageAndi
Copy link
Contributor Author

@rainersigwald I am working on a repro right now.

@SabotageAndi
Copy link
Contributor Author

@rainersigwald I have it.

You can find it here: https://github.com/SabotageAndi/GH1912

Simply build it with the included build.ps1 script.

If building with .NET Core SDK 3.1.200 I get following output:

PS C:\work\GH1912Repro> .\build.ps1
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 241,96 ms for C:\work\GH1912Repro\Common\Common.csproj.
  Restore completed in 298,88 ms for C:\work\GH1912Repro\MSBuildTask\MSBuildTask.csproj.
  Common -> C:\work\GH1912Repro\Common\bin\Debug\netstandard2.0\Common.dll
  MSBuildTask -> C:\work\GH1912Repro\MSBuildTask\bin\Debug\netcoreapp2.0\MSBuildTask.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.53
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 35,71 ms for C:\work\GH1912Repro\MSBuildTask\MSBuildTask.csproj.
  Restore completed in 35,71 ms for C:\work\GH1912Repro\Common\Common.csproj.
  Restore completed in 174,62 ms for C:\work\GH1912Repro\App\App.csproj.
  Restore completed in 174,59 ms for C:\work\GH1912Repro\Plugin\Plugin.csproj.
  Common -> C:\work\GH1912Repro\Common\bin\Debug\netstandard2.0\Common.dll
  MSBuildTask -> C:\work\GH1912Repro\MSBuildTask\bin\Debug\netcoreapp2.0\MSBuildTask.dll
  Plugin -> C:\work\GH1912Repro\Plugin\bin\Debug\netstandard2.0\Plugin.dll
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: The "AssemblyLoadTask" task failed unexpectedly.
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: File name: 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, BooleaC:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntC:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Attribute.GetCustomAttributes(Assembly element, Boolean inherit)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(Assembly element)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at MSBuildTask.AssemblyLoadTask.Execute() in C:\work\GH1912Repro\MSBuildTask\AssemblyLoadTask.cs:line 19
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:

Build FAILED.

C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: The "AssemblyLoadTask" task failed unexpectedly.
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018: File name: 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Attribute.GetCustomAttributes(Assembly element, Boolean inherit)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(Assembly element)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at MSBuildTask.AssemblyLoadTask.Execute() in C:\work\GH1912Repro\MSBuildTask\AssemblyLoadTask.cs:line 19
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:
C:\work\GH1912Repro\App\App.csproj(15,5): error MSB4018:
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.23

With .NET Core SDK 3.1.102 I get this output:

Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 182,73 ms for C:\work\GH1912Repro\MSBuildTask\MSBuildTask.csproj.
  Restore completed in 182,73 ms for C:\work\GH1912Repro\Common\Common.csproj.
  Common -> C:\work\GH1912Repro\Common\bin\Debug\netstandard2.0\Common.dll
  MSBuildTask -> C:\work\GH1912Repro\MSBuildTask\bin\Debug\netcoreapp2.0\MSBuildTask.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.37
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 29,24 ms for C:\work\GH1912Repro\Common\Common.csproj.
  Restore completed in 29,44 ms for C:\work\GH1912Repro\MSBuildTask\MSBuildTask.csproj.
  Restore completed in 141,4 ms for C:\work\GH1912Repro\App\App.csproj.
  Restore completed in 141,39 ms for C:\work\GH1912Repro\Plugin\Plugin.csproj.
  Common -> C:\work\GH1912Repro\Common\bin\Debug\netstandard2.0\Common.dll
  MSBuildTask -> C:\work\GH1912Repro\MSBuildTask\bin\Debug\netcoreapp2.0\MSBuildTask.dll
  Plugin -> C:\work\GH1912Repro\Plugin\bin\Debug\netstandard2.0\Plugin.dll
  App -> C:\work\GH1912Repro\App\bin\Debug\netcoreapp3.1\App.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.42

I hope this helps you.

@rainersigwald
Copy link

@SabotageAndi that is an amazing repro! Thank you! I reproduce the problem with it and will take a look.

@rainersigwald
Copy link

One quick note: with @SabotageAndi's repro, MSBUILDSINGLELOADCONTEXT=1 does appear to work around the problem. I would recommend that over downgrading VS or the SDK.

@SabotageAndi
Copy link
Contributor Author

@rainersigwald any news on this issue?

@rainersigwald
Copy link

No news yet, sorry. Filed dotnet/msbuild#5202 to keep it top of mind for my team.

@SabotageAndi
Copy link
Contributor Author

Do you think we could do something on our side to get around the issue? More and more people are hitting this issue.

@rainersigwald
Copy link

Your repro case uses Assembly.LoadFile(path) to load a dependent assembly. On .NET Core 3.1 (at least, probably since 2.0?), this creates a new AssemblyLoadContext--on my machine it's named Assembly.LoadFile(S:\repro\SpecFlowOSS\SpecFlow\issues\1912\Plugin\bin\debug\netstandard2.0\Plugin.dll).

The docs for Assembly.LoadFile say

LoadFile does not load files into the load-from context, and does not resolve dependencies using the load path, as the LoadFrom method does.

That's exactly what's happening here: it's failing to resolve dependencies using the path of the loaded file.

This worked before 3.1.200/MSBuild 16.5, because MSBuild installed an assembly load hook into the default ALC that would load dependencies from "any directory next to a loaded task assembly".

If I use LoadFrom instead,

diff --git a/MSBuildTask/AssemblyLoadTask.cs b/MSBuildTask/AssemblyLoadTask.cs
index d0c5010..fa497ba 100644
--- a/MSBuildTask/AssemblyLoadTask.cs
+++ b/MSBuildTask/AssemblyLoadTask.cs
@@ -14,7 +14,7 @@ namespace MSBuildTask
         public override bool Execute()
         {
             var path = Path.Combine(Environment.CurrentDirectory, "..", "Plugin", "bin", "debug", "netstandard2.0", "Plugin.dll");
-            var assembly = Assembly.LoadFile(path);
+            var assembly = Assembly.LoadFrom(path);
             
             var customAttributes = assembly.GetCustomAttributes();
             var pluginAttribute = (PluginMarkerAttribute)customAttributes.SingleOrDefault(a => a is PluginMarkerAttribute);

your repro case works fine.

I think that's the right way to go. I first thought that you might be using LoadFile to work around the original problem that caused us to introduce ALCs for tasks--being able to load the same task in multiple versions. But LoadFile doesn't do that, because the transitive references get loaded into the default ALC anyway.

@SabotageAndi
Copy link
Contributor Author

Thanks for the input. I will try to use Assembly.LoadFrom and see if this changes something.

@magicben
Copy link

Thanks for the input. I will try to use Assembly.LoadFrom and see if this changes something.

Hi @SabotageAndi , hope everything is fine on your side.
Did you have time to work on this fix?
Take care.

@SabotageAndi
Copy link
Contributor Author

@magicben I am still looking into it. No new news yet.

@SabotageAndi SabotageAndi added the SpecFlow Team Backlog this issue are in the backlog of the SpecFlow Team label May 4, 2020
@SabotageAndi
Copy link
Contributor Author

Some status updates:
We (@tzongithub and me) started with the first step to fix this issue. That is to change our MSBuild task from .NET Standard 2.0 to .NET Core 2.1. PR: #1968

The next step will be to change the Assembly loading code.

@SabotageAndi
Copy link
Contributor Author

We merged the last PR for this to fix. Build is now running to create new packages.
When the release pipeline is finished, you find SpecFlow 3.3-beta packages on NuGet.org.

@CurlyFire
Copy link

@SabotageAndi Great! How long does a release stay in beta usually ?

@SabotageAndi
Copy link
Contributor Author

@CurlyFire Depends from version to version. This will be at least 3 weeks in beta. We have some additional changes planned in our next iteration (starts next Tuesday).

@SabotageAndi
Copy link
Contributor Author

We published a first 3.3-beta package to NuGet.org (https://www.nuget.org/packages/SpecFlow/3.3.15-beta) which a fix for this.

Please try it out and give us feedback if it is now working for you.

@js8080
Copy link

js8080 commented May 8, 2020

@SabotageAndi seems to be working for me.

benbelow added a commit to Anthony-Nolan/Atlas that referenced this issue May 11, 2020
@smushtaq
Copy link

We published a first 3.3-beta package to NuGet.org (https://www.nuget.org/packages/SpecFlow/3.3.15-beta) which a fix for this.

Please try it out and give us feedback if it is now working for you.

worked for me. I used 3.3.16-beta

@MarcWils
Copy link

Works like a charm.

@alanta
Copy link

alanta commented May 12, 2020

3.3.16-beta works for me as well

@arkiaconsulting
Copy link

Confirmed 3.3.16-beta

@SabotageAndi
Copy link
Contributor Author

Thanks for the feedback. I am closing now this issue.

gregkalapos added a commit to elastic/apm-agent-dotnet that referenced this issue Jun 8, 2020
* Add Elastisearch to team shared dictionary

* initial commit

* clean up implemntations and error reporting

* always add frames

* Initial stab at tests using prerelease package

* Linux compilation fixes being bit by: SpecFlowOSS/SpecFlow#1912

* Introduce more unit tests around Elasticsearch integration

* remove unused variable

* Remove dependency on Elastic.Managed.Ephemeral

Only used in example project, switched to one that talks to
elastic/apm-integration-testing.

* bump Elasticsearch.Net reference

* Apply suggestions from code review

Co-authored-by: Gergely Kalapos <gergo@kalapos.net>

* Log DiagnosticEventKey on Trace

* Try catch around calling OnNext()

* update failing test, assertion could never be satisfied, Added assertions on reported exception

Co-authored-by: Gergely Kalapos <gergo@kalapos.net>
AdCodicem pushed a commit to AdCodicem/SpecFlow.DependencyInjection that referenced this issue Jun 9, 2020
Mutualization of Specflow reference.
Using Specflow 3.3.22-beta (only for test project) to resolve the following issue SpecFlowOSS/SpecFlow#1912
imzyk added a commit to imzyk/UI_Automation_Framwork that referenced this issue Jul 10, 2020
Update DevOps Pipeline to workaround SpecFlowOSS/SpecFlow#1912
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Generator msbuild .NET Core Support SpecFlow Team Backlog this issue are in the backlog of the SpecFlow Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.