0

I am having a problem where I have private field and public property. This is the way I have decorated my class and properties.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml.Serialization;

    [DataContract]
    [KnownType(typeof(XDocument))]
    public abstract class DocumentBase
    {
        #region Public Contructors

        /// <summary>
        /// Initialises a new instance of the DocumentBase class
        /// </summary>
        protected DocumentBase()
        {
            Id = Guid.NewGuid();
            Roles = new List<string>();
        }

        #endregion

        #region Private Fields

        /// <summary>
        /// Holds the filename of the document
        /// </summary>
        [DataMember]
        private string fileName;

        private IFileNameCleaner fileNameCleaner;

        #endregion

        #region Protected Properties

        protected IFileNameCleaner FileNameCleaner
        {
            get
            {
                return fileNameCleaner;
            }

            set
            {
                fileNameCleaner = value;
            }
        }

        #endregion

        #region Public Properties

        [DataMember]
        public string FileName
        {
            get
            {
                string newFileName = this.fileName;
                if (FileNamePrefix > 0)
                {
                    newFileName = FileNamePrefix + "_" + fileName;
                }

                return fileNameCleaner.FileName(newFileName);
            }
          private  set
            {
                fileName = value;
            }
        }

Error:

FileName is not getting Serialized, Can anyone advise me what is being missed?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Hari Gillala
  • 11,736
  • 18
  • 70
  • 117
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jul 17 '13 at 18:58

1 Answers1

0

From filename property, you return FileName property of FileNameCleaner. Is this returned filenamecleaner.FileName property serializable?

vibhu
  • 1,657
  • 2
  • 15
  • 19