我在尝试对客户端进行回调时得到CommunicationException
,我知道问题出在这个类中,虽然我无法弄清楚哪个成员在序列化时遇到了麻烦。
[DataContract]
public sealed class DirectoryInformation : FileSystemInfo
{
public override void Delete()
{
Directory.Delete(FullName);
}
[DataMember]
public override string Name
{
get { return Path.GetFileName(FullName); }
}
[DataMember]
public override bool Exists
{
get { return Directory.Exists(FullName); }
}
[DataMember]
public int Size { get; private set; }
#region Ctor
public DirectoryInformation(string directory)
{
FullPath = directory;
Refresh();
CalculateDirectorySize(directory);
}
public DirectoryInformation()
{
}
#endregion
#region Private Methods
private void CalculateDirectorySize(string directory)
{
if (!IsDirectoryAccessible(directory)) return;
Size = Size + (int) Directory.GetFiles(directory).Select(x => new FileInfo(x)).Sum(x => x.Length);
foreach (var dir in Directory.GetDirectories(directory))
CalculateDirectorySize(dir);
}
private static bool IsDirectoryAccessible(string directory)
{
try
{
Directory.GetFiles(directory);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
}
#endregion
}
我已经检查过,它不是FileSystemInfo
的成员之一,因为即使在删除继承时问题仍然存在。我已经确定我为所有成员分配了DataMember
属性,并且有一个标准的构造函数。
我认为导致问题的原因是我不知道存在的问题,但它可能是什么?