This project is read-only.

MetadataFileReference and Assembly not found in VS2015

Topics: APIs, General
Jan 15, 2015 at 8:27 PM
I was trying to migrate several of my projects from VS2013 to VS2015. I found out that there are problems with MetadataFileReference and Assembly when I'm trying to make a compilation object from a tree within Diagnostic API.
public void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context) {
var tree = context.Tree;
var Mscorlib = new MetadataFileReference(typeof(object).Assembly.Location);
var compilation = CSharpCompilation.Create("MyCompilation",
                syntaxTrees: new[] { tree }, references: new[] { Mscorlib });
var semanticModel = compilation.GetSemanticModel(tree);
What are their changes? Any idea would be appreciated!
Jan 15, 2015 at 8:40 PM
we added factories to MetadataReference instead of having you create the type yourself. Look at MetadataReference.CreateFromAssembly
var Mscorlib = MetadataReference.CreateFromAssembly(typeof(object).Assembly);
Marked as answer by bburg89 on 1/15/2015 at 2:04 PM
Jan 15, 2015 at 8:49 PM
It works well for replacing MetadataFileReference, but I still have an error with the Assembly saying it could not be found.
Jan 15, 2015 at 9:54 PM
I assume you are running is inside of a portable class library? In that case you need to use GetTypeInfo from System.Reflection.
Marked as answer by bburg89 on 1/15/2015 at 2:04 PM