【发布时间】:2011-05-18 20:59:52
【问题描述】:
作为 .Net 开发人员,我遇到了最奇怪的问题。我正在编译一个库,该库在 UserInfo 类中具有新添加的属性 DeviceID。该库在内部使用该类型并且它是新属性就好了,但是当我尝试从另一个库中引用它时,编译器会返回一个编译器错误声明
'library.UserInfo' does not contain a definition for 'DeviceID' and no extension
method 'DeviceID' accepting a first argument of type 'library.UserInfo' could
be found
即使我的类定义看起来像:
public class UserInfo
{
public static UserInfo Current
{
get
{
if (UserInfoPrincipal.Current != null)
{
return UserInfoPrincipal.Current.UserData;
}
else
{
return null;
}
}
}
public string UserID { get; set; }
public string DeviceID { get; set; }
public string MikeLiUserID { get; set; }
public string TransactionServer { get; set; }
public string ApplicationKey { get; set; }
public string IpAddress { get; set; }
}
违规代码如下:
internal LogDetail BuildLogDetail(LogType entryType, string message)
{
return new LogDetail
{
ActingUserID = UserInfo.Current.UserID,
ActingDeviceID = UserInfo.Current.DeviceID,
ApplicationKey = UserInfo.Current.ApplicationKey,
IpAddress = UserInfo.Current.IpAddress,
EntryType = entryType,
OwnerID = UserInfo.Current.UserID,
LogData = message
};
}
我想指出,UserInfo 类的所有其他成员都正确地通过了编译器,只是今天添加的 DeviceID 导致了问题。我尝试过 Clean All,我尝试过从 TFS 刷新所有内容,手动删除两个项目的 obj 和 bin 目录……还没有任何效果。
更新:此代码是库的一部分,可以正常工作:
public class UserInfoPrincipal : IPrincipal
{
public static UserInfoPrincipal Current
{
get
{
if (Thread.CurrentPrincipal is UserInfoPrincipal)
return (UserInfoPrincipal)Thread.CurrentPrincipal;
else
return null;
}
}
...
internal UserInfo UserData
{
get { return _userInfo; }
}
public string DeviceID
{
get { return _userInfo.DeviceID; }
}
...
}
【问题讨论】:
-
我发现 Visual Studio 有时需要重启……你试过了吗?
-
竟然连电脑都重启了
-
@thaBadDawg - 重新启动整个计算机?伙计,这意味着它是一个严重的问题! :) 既然您提到了 TFS - 是否有另一台开发机器可以从中获取源代码并尝试在那里构建它?或者甚至在您的机器上设置另一个工作区?
-
这个问题最初出现在另一个开发者的机器上,让他检查了有问题的代码并试图在我的机器上处理它。两台机器有同样的问题意味着我很可能忽略了一些非常简单的东西,我什至不想看它。
-
@Jim - 更好的方法是观察 msbuild diag 输出并查看它解析了哪个引用。
标签: c# .net compiler-errors