Xamarin Android runtime C# compilation

夙愿已清 提交于 2019-12-08 07:07:30

问题


I am trying to compile a simple code in C# using Microsoft.CodeAnalysis.CSharp.

The problem is in trying to add the reference to mscorlib.dll. As the CreateFromAssembly method of the MetadataReference class is deprecated I am trying to use the CreateFromFile method (as suggested):

var mscorlibAssembly = Assembly.Load(new AssemblyName("mscorlib.dll")).ManifestModule.Assembly;
var mscorlibref = MetadataReference.CreateFromFile(mscorlibAssembly.Location);
result.Add(mscorlibref);

The Location property of the assembly returns "mscorlib.dll" and not the full path causing the error: System.IO.FileNotFoundException: Could not find file "/mscorlib.dll"

How can I load the correct MSCorLib reference to be able to use CSharpCompilation?

来源:https://stackoverflow.com/questions/51025921/xamarin-android-runtime-c-sharp-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!