![](/img/trans.png)
[英]Reference to type 'Assembly' claims it is defined in 'System.Runtime', but it could not be found
[英]Reference to type 'CancellationToken' claims it is defined in 'System.Runtime'
我正在嘗試使用Roslyn api生成一些類,但是由於該錯誤,我無法成功編譯生成的代碼。 聽起來:
error CS7069: Reference to type 'CancellationToken' claims it is defined in 'System.Runtime', but it could not be found
我想做的是:
var objLocation = typeof(object).GetTypeInfo().Assembly.Location;
var path = new FileInfo(objLocation);
var directory = path.Directory;
Compilation = Compilation.AddReferences(MetadataReference.CreateFromFile(objLocation));
Compilation = Compilation.AddReferences(MetadataReference.CreateFromFile(Path.Combine(directory.FullName, "System.dll")));
Compilation = Compilation.AddReferences(MetadataReference.CreateFromFile(Path.Combine(directory.FullName, "System.Runtime.dll")));
據我所知, System.Runtime.dll
只是引用不同庫的占位符,因此我不明白為什么會出現該消息以及為什么編譯器會在此處查找該類型。
可以給我點什么嗎?
聽起來您正在為.net core進行編譯。
CancellationToken駐留在mscorlib.dll中,因此您也需要引用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.