Open fubar-coder opened 7 years ago
@tmat Do you understand the dependencies here?
@tmat can you help with the dependencies here?
@fubar-coder Do you have {AssemblyName}.xunit.runner.json
file with
{
"shadowCopy": false
}
In the output directory?
Closing as we can't help here without a response. @fubar-coder Please answer @tmat's question above if you're still blocked.
I'll try the suggestion from @tmat
@Pilchie @tmat No, I don't have such a file in the output. Here's an example project: test-xunit.zip
Does it work when you add it?
No, it doesn't work. I added a both a TestXUnit.xunit.runner.json
and TestXUnit.dll.xunit.runner.json
file to the bin\Debug\net46
folder. The exception is the same.
@tmat: Ping?
This is happening to me too. I could get an absolute minimal repro for my scenario (an MSBuild task that uses Roslyn).
From the attached readme:
Result: exception thrown:
System.Reflection.ReflectionTypeLoadException occurred
HResult=0x80131602
Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source=mscorlib
StackTrace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at System.Composition.Hosting.ContainerConfiguration.<WithAssemblies>b__0(Assembly a)
at System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create(IEnumerable`1 assemblies)
at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.get_DefaultHost()
at Microsoft.CodeAnalysis.AdhocWorkspace..ctor()
at CustomTask.UseRoslyn.Execute() in C:\Delete\WrongDependencies\CustomTask\UseRoslyn.cs:line 11
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
with a LoaderExceptions showing the following Fusion log:
=== Pre-bind state information ===
LOG: DisplayName = System.Collections.Immutable, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Reflection.Metadata, Version=1.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Collections.Immutable, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/System.Collections.Immutable.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/System.Collections.Immutable/System.Collections.Immutable.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/System.Collections.Immutable.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/System.Collections.Immutable/System.Collections.Immutable.EXE.
LOG: Attempting download of new URL file:///C:/Delete/WrongDependencies/CustomTask/bin/Debug/net461/System.Collections.Immutable.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
LOG: Attempting download of new URL file:///C:/Delete/WrongDependencies/CustomTask/bin/Debug/net461/System.Collections.Immutable/System.Collections.Immutable.DLL.
LOG: Attempting download of new URL file:///C:/Delete/WrongDependencies/CustomTask/bin/Debug/net461/System.Collections.Immutable.EXE.
LOG: Attempting download of new URL file:///C:/Delete/WrongDependencies/CustomTask/bin/Debug/net461/System.Collections.Immutable/System.Collections.Immutable.EXE.
"Fix":
$(VsInstallRoot)\MSBuild\15.0\Bin\MSBuild.exe.config
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.2.0.0" newVersion="1.2.1.0" />
</dependentAssembly>
Result: everything now works as expected.
FWIW, you can see this is happening to others, i.e. https://github.com/AArnott/CodeGeneration.Roslyn/commit/7b268c2384ba05367026a0e49147c5ed49a3bdda
I just hit another one after that: System.IO.FileSystem
is exactly in the same situation, with 4.0.1.0
being loaded instead of 4.0.2.0
:
The fix in this case is:
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="4.0.1.0" newVersion="4.0.2.0" />
</dependentAssembly>
@DustinCampbell can you help take a look at this too? Maybe we need an end to end sample of how to use MSBuildWorkspace on a machine with only VS 2017. (Just thinking about the .NET Framework piece here, without the .NET Core complications)
In my case, it's an AdhocWorkspace
Version Used:
Steps to Reproduce:
Either:
TargetFramework
fromnetcoreapp1.1
tonet46
Microsoft.CodeAnalysis
version 2.0.0 to the unit test projectMSBuildWorkspace
in the test method usingMSBuildWorkspace.Create();
Or:
Microsoft.CodeAnalysis
version 2.0.0 to the unit test projectMSBuildWorkspace
in the test method usingMSBuildWorkspace.Create();
Expected Behavior:
No error
Actual Behavior:
A
System.Reflection.ReflectionTypeLoadException
is thrown. TheLoaderExceptions
contains the following fusion log:This log shows that
System.Reflection.Metadata
version 1.4.1.0 tried to loadSystem.Collections.Immutable
version 1.2.0.0, but I cannot downgrade to this version, because Roslyn requires 1.2.1 (NuGet package version 1.3.1).Stack trace:
Upgrading the package
Microsoft.Composition
doesn't work, because it complains with aFileLoadException
that the assemblySystem.Composition.TypedParts
version 1.0.27.0 couldn't be loaded.This is the stack trace:
Using an app.config for the test project doesn't work. The
.dll.config
gets copied to the output folder, but the binding redirect isn't picked up.I think that the problem is two-fold:
Fun fact: Using a .NET Framework console application works without error.