Has anyone successfully managed to run the WPF RoslynPad editor in a Visual Studio Extension (VSIX) (FYI: I'm using Visual Studio 2015 Enterprise)?
When trying to initialize the Roslyn host in a VSIX like this:
var host = new RoslynHost(additionalAssemblies: new[]
{
Assembly.Load("RoslynPad.Roslyn.Windows"),
Assembly.Load("RoslynPad.Editor.Windows")
});
I get the following error:
Could not load file or assembly 'System.Collections.Immutable, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Collections.Immutable, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
The stack trace is:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at RoslynPad.Roslyn.RoslynHost.<>c.<.ctor>b__20_0(Assembly x)
at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
at RoslynPad.Roslyn.RoslynHost..ctor(NuGetConfiguration nuGetConfiguration, IEnumerable`1 additionalAssemblies, RoslynHostReferences references)
Note that the same bit of code works in the "RosylnPadPelSample" WPF application provided by RoslynPad.
What strikes me is that it's looking for System.Collections.Immutable version 1.2.0.0 (I believe this is a dependency in System.Reflection.Metadata.dll) as the sample application does NOT include this file. It has version 1.2.0.1 (the same version as my extension), but has a binding redirect that compensates for its ommission:
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
If I explicitly add System.Collections.Immutable
version 1.2.0.0 as a reference, then I get the same exception from RoslynPad, but this time it can't find System.Collections.Immutable
version 1.2.0.1! The binding redirect doesn't seem to take effect in Visual Studio Extensions. Does anyone know how to accomplish a binding redirect in Visual Studio Extensions or how to solve this issue?