我在通过 .NET 远程处理通道读取属性时遇到问题。这是我的课的开始:
[Serializable]
public class MachineID
{
private string mySystemDeviceSerial = null;
/// <summary>
/// Returns the hard drive serial that Windows is installed on.
/// </summary>
public string SystemDeviceSerial
{
get { return mySystemDeviceSerial; }
}
private string mySystemName = null;
/// <summary>
/// Returns the current name of the system.
/// </summary>
public string SystemName
{
get { return mySystemName; }
}
private string myLastError = string.Empty;
/// <summary>
/// Returns the last error that occurred. Returns string.Empty if no error has occurred.
/// </summary>
public string LastError
{
get { return myLastError; }
}
private int myPort = -2;
public int Port
{
get { return this.myPort; }
set { this.myPort = value; }
}
所有属性都可以在本地计算机上正常访问。但是,当我尝试通过 .NET 远程处理通道从客户端读取 Port 属性时,我没有得到分配给 myPort 的值,而是初始值 -2。我对此感到困惑,因为所有字符串属性都可以正常读取。有任何想法吗?我没有正确序列化这个类吗?
值得注意的是,为了使这个类和成员可序列化,我所做的只是在类的顶部添加 [Serializable] 属性。我不确定这是否是正确的方法,所以也许这可能是问题的一部分?