我已将我的问题简化为以下代码。
using WeinCad.Plugin.MoineauMachinePath;
namespace WeinCad.Plugin.Foo
{
public class Foo
{
// This line is a compiler error
// (Cannot resolve symbol MoineauMachinePath )
private WeinCad.Plugin.MoineauMachinePath.MachinePathSolverPropertiesViewModel X;
// Implicity referenced it is ok
private MachinePathSolverPropertiesViewModel Y;
}
}
如果我使用对类的显式引用,则会出现编译器错误。为了证明命名空间是正确的,我还将命名空间导入范围并隐式引用该类。只有显式引用有误。
编辑
intellisense 显示有一个像这样嵌套的命名空间。这将是问题的根源。不确定它是如何编码的。
编辑
问题的根源是损坏的 Resources.Designer.cs 文件。
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WeinCad.Plugin.WeinCad.Plugin.BasicFolders.Properties
{
using System;
不知道这是怎么发生的。删除资源文件然后重新创建我得到
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WeinCad.Plugin.BasicFolders.Properties {
using System;
没有讨厌的重复。关于这是如何发生的,这仍然是一个悬而未决的问题。
请您参考如下方法:
该错误消息表明当前范围内有一个 WeinCad.Plugin ,即 WeinCad.Plugin.Foo.Foo.WeinCad.Plugin,或 WeinCad.Plugin.Foo.WeinCad.Plugin。当编译器寻找 WeinCad.Plugin 时,它会首先在本地范围内查找,只有在找不到匹配项时才会在全局范围内查找。
最简单和最正确的解决方法是:不要有在其内部重复名称的作用域(那只是自找麻烦)。另一种选择是明确指定全局范围,使用完整类型名称前的 global:: 前缀,即 global::WeinCad.Plugin。随便。
