1

I am getting a CommunicationException when trying to do a callback to a client, I know that the problem lies within this class, although I can't figure out what member is having trouble being serialized.

[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
    }

I have already checked and it is not one of the members of FileSystemInfo, since the problem persisted even when removing the inheritance. I already made sure I am assigning all the members with DataMember attribute and there is a standard contructor.

I think what is causing the problem is something I am not aware of the existence, but what could it be?

Krekkon
  • 1,349
  • 14
  • 35
Bruno Klein
  • 3,217
  • 5
  • 29
  • 39

0 Answers0