It appears that for some reason, Roslyn on .NET Core is throwing an error when a class that inherits from Dictionary
is accessed.
CS0012: The type 'Dictionary<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
My syntax tree looks like so:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using JQL.Core;
namespace RoslynCompileSample
{
public class Writer
{
public object LinqIt(string outKey, Dictionary<string
IEnumerable<TestClass>> db)
{
return db[outKey] = ({$linq
});
}
}
}
And my references:
MetadataReference[] references = new MetadataReference[]
{
MetadataReference.CreateFromFile(typeof(JQLQuery).Assembly.Location),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Runtime.AssemblyTargetedPatchBandAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(DynamicAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Collections.Generic.Dictionary<,>).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Collections.Generic.Dictionary<string,object>).Assembly.Location)
};
My class
public class TestClass : Dictionary<string, object>
{
public int age { get; set; }
public TestClass()
{
this.age = 10;
}
}
Dictionary works if the object is defined from within the Roslyn SyntaxTree. If any Dictionary or inherited objects are passed in, I get the error.
Any idea what may be causing this? My collections version is actually 4.3.0 so not sure why it's even asking for a lower version.