【发布时间】:2016-01-27 12:22:46
【问题描述】:
我已经使用 Unity 5 一年了,一切正常,直到上周我们有了将 IDE 更新到 5.3.1 版本的想法。
现在编译器显示两个错误:
The name `Dictionary' does not exist in the current context.
The name `Items' does not exist in the current context.
两者都本地化为一个简单的 KeyedCollection
public class CommandProcessQueueCollection : KeyedCollection<int, CommandProcessQueue>
{
public bool TryGetQueue(int id, out CommandProcessQueue queue)
{
if (Dictionary != null)
{
return Dictionary.TryGetValue(id, out queue);
}
foreach (var i in Items)
{
var k = GetKeyForItem(i);
if (Comparer.Equals(id, k))
{
queue = i;
return true;
}
}
queue = default(CommandProcessQueue);
return false;
}
protected override int GetKeyForItem(CommandProcessQueue queue)
{
return queue.Id;
}
}
经过多次尝试,事情变得更加棘手,因为完全相同的代码已在 5 台安装了 5.3.1 的不同机器上编译。
嗯,5 个中有 2 个被证明可以编译没有任何错误。
此外,msbuild 似乎编译代码也没有任何错误。
在机器之间,Mono 用于编译的 .NetFramework 可能存在差异。
你对这个奇怪的问题有什么想法吗?
PS:我正在添加 using System.Collections.ObjectModel,并且我当前在 Unity 编辑器中的 API 兼容性选项设置为 .NET 2.0。
【问题讨论】:
-
FWIW 您是否尝试过在代码中将
Dictionary明确替换为System.Collections.ObjectModel.Dictionary? (甚至以为你是using。)可能是冲突造成的灾难?