public void Serialize(Stream serializationStream, object graph)
        {
            // don't refactor the 'throw' into a helper method; linker will have difficulty trimming
            if (!LocalAppContextSwitches.BinaryFormatterEnabled)
            {
                throw new NotSupportedException(SR.BinaryFormatter_SerializationDisallowed);
            }

            ArgumentNullException.ThrowIfNull(serializationStream);

            var formatterEnums = new InternalFE()
            {
                _typeFormat         = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat     = _assemblyFormat,
            };

            try
            {
                BinaryFormatterEventSource.Log.SerializationStart();
                var sow = new ObjectWriter(_surrogates, _context, formatterEnums, _binder);
                BinaryFormatterWriter binaryWriter = new BinaryFormatterWriter(serializationStream, sow, _typeFormat);
                sow.Serialize(graph, binaryWriter);
                _crossAppDomainArray = sow._crossAppDomainArray;
            }
            finally
            {
                BinaryFormatterEventSource.Log.SerializationStop();
            }
        }
Exemple #2
0
        internal object Deserialize(Stream serializationStream, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }
            if (serializationStream.CanSeek && (serializationStream.Length == 0))
            {
                throw new SerializationException(SR.Serialization_Stream);
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat = _assemblyFormat,
                _securityLevel = _securityLevel,
            };

            var reader = new ObjectReader(serializationStream, _surrogates, _context, formatterEnums, _binder)
            {
                _crossAppDomainArray = _crossAppDomainArray
            };
            var parser = new BinaryParser(serializationStream, reader);
            return reader.Deserialize(parser, check);
        }
Exemple #3
0
        internal object Deserialize(Stream serializationStream, HeaderHandler handler, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }
            if (serializationStream.CanSeek && (serializationStream.Length == 0))
            {
                throw new SerializationException(SR.Serialization_Stream);
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat         = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat     = _assemblyFormat,
                _securityLevel      = _securityLevel,
            };

            var reader = new ObjectReader(serializationStream, _surrogates, _context, formatterEnums, _binder)
            {
                _crossAppDomainArray = _crossAppDomainArray
            };
            var parser = new BinaryParser(serializationStream, reader);

            return(reader.Deserialize(handler, parser, check));
        }
Exemple #4
0
        [System.Security.SecurityCritical]  // auto-generated
        internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream));
            }
            Contract.EndContractBlock();

            if (serializationStream.CanSeek && (serializationStream.Length == 0))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));
            }

            SerTrace.Log(this, "Deserialize Entry");
            InternalFE formatterEnums = new InternalFE();

            formatterEnums.FEtypeFormat         = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat     = m_assemblyFormat;
            formatterEnums.FEsecurityLevel      = m_securityLevel;

            ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder);

            sor.crossAppDomainArray = m_crossAppDomainArray;
            return(sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage));
        }
 internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     this.m_surrogates = selector;
     this.m_context = context;
     this.m_binder = binder;
     this.formatterEnums = formatterEnums;
     this.m_objectManager = new SerializationObjectManager(context);
 }
Exemple #6
0
 internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     this.m_surrogates    = selector;
     this.m_context       = context;
     this.m_binder        = binder;
     this.formatterEnums  = formatterEnums;
     this.m_objectManager = new SerializationObjectManager(context);
 }
 internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     _currentId      = 1;
     _surrogates     = selector;
     _context        = context;
     _binder         = binder;
     _formatterEnums = formatterEnums;
     _objectManager  = new SerializationObjectManager(context);
 }
 internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     _currentId = 1;
     _surrogates = selector;
     _context = context;
     _binder = binder;
     _formatterEnums = formatterEnums;
     _objectManager = new SerializationObjectManager(context);
 }
Exemple #9
0
        internal ObjectReader(Stream stream, ISurrogateSelector?selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder?binder)
        {
            ArgumentNullException.ThrowIfNull(stream);

            _stream         = stream;
            _surrogates     = selector;
            _context        = context;
            _binder         = binder;
            _formatterEnums = formatterEnums;
        }
        internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _stream = stream;
            _surrogates = selector;
            _context = context;
            _binder = binder;
            _formatterEnums = formatterEnums;
        }
        internal ObjectReader(Stream stream, ISurrogateSelector?selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder?binder)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _stream         = stream;
            _surrogates     = selector;
            _context        = context;
            _binder         = binder;
            _formatterEnums = formatterEnums;
        }
        // XMLObjectWriter Constructor
        internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
        {
            m_currentId = 1;
            m_surrogates = selector;
            m_context = context;
            m_binder = binder;
            this.formatterEnums = formatterEnums;
            m_objectManager = new SerializationObjectManager(context);
            SerTrace.InfoLog(
                            formatterEnums.FEtypeFormat +" "+
                            ((Enum)formatterEnums.FEserializerTypeEnum));


        }
        public object Deserialize(Stream serializationStream)
        {
            // don't refactor the 'throw' into a helper method; linker will have difficulty trimming
            if (!LocalAppContextSwitches.BinaryFormatterEnabled)
            {
                throw new NotSupportedException(SR.BinaryFormatter_SerializationDisallowed);
            }

            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }
            if (serializationStream.CanSeek && (serializationStream.Length == 0))
            {
                throw new SerializationException(SR.Serialization_Stream);
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat         = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat     = _assemblyFormat,
                _securityLevel      = _securityLevel,
            };

            var reader = new ObjectReader(serializationStream, _surrogates, _context, formatterEnums, _binder)
            {
                _crossAppDomainArray = _crossAppDomainArray
            };

            try
            {
                BinaryFormatterEventSource.Log.DeserializationStart();
                var parser = new BinaryParser(serializationStream, reader);
                return(reader.Deserialize(parser));
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new SerializationException(SR.Serialization_CorruptedStream, e);
            }
            finally
            {
                BinaryFormatterEventSource.Log.DeserializationStop();
            }
        }
Exemple #14
0
        internal void Serialize(Stream serializationStream, object graph, Header[] headers, bool fCheck)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream }));
            }
            InternalFE formatterEnums = new InternalFE {
                FEtypeFormat         = this.m_typeFormat,
                FEserializerTypeEnum = InternalSerializerTypeE.Binary,
                FEassemblyFormat     = this.m_assemblyFormat
            };
            ObjectWriter   objectWriter = new ObjectWriter(this.m_surrogates, this.m_context, formatterEnums, this.m_binder);
            __BinaryWriter serWriter    = new __BinaryWriter(serializationStream, objectWriter, this.m_typeFormat);

            objectWriter.Serialize(graph, headers, serWriter, fCheck);
            this.m_crossAppDomainArray = objectWriter.crossAppDomainArray;
        }
Exemple #15
0
        // XMLObjectWriter Constructor
        internal ObjectWriter(Stream stream, ISurrogateSelector selector, StreamingContext context,InternalFE formatterEnums)
        {
            if (stream==null)
            {
                throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream"));                
            }

            m_currentId = 1;
            m_stream=stream;
            m_surrogates = selector;
            m_context = context;
            this.formatterEnums = formatterEnums;
            SerTrace.InfoLog(
                            formatterEnums.FEtypeFormat +" "+
                            ((Enum)formatterEnums.FEserializerTypeEnum));


        }
Exemple #16
0
        internal void Serialize(Stream serializationStream, object graph, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat = _assemblyFormat,
            };

            var sow = new ObjectWriter(_surrogates, _context, formatterEnums, _binder);
            BinaryFormatterWriter binaryWriter = new BinaryFormatterWriter(serializationStream, sow, _typeFormat);
            sow.Serialize(graph, binaryWriter, check);
            _crossAppDomainArray = sow._crossAppDomainArray;
        }
Exemple #17
0
        // Commences the process of serializing the entire graph.  All of the data (in the appropriate format
        // is emitted onto the stream).
        internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream", String.Format(Environment.GetResourceString("ArgumentNull_WithParamName"), serializationStream));
            }
            SerTrace.Log(this, "Serialize Entry");

            InternalFE formatterEnums = new InternalFE();

            formatterEnums.FEtypeFormat         = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat     = m_assemblyFormat;
            ObjectWriter   sow          = new ObjectWriter(serializationStream, m_surrogates, m_context, formatterEnums);
            __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat);

            sow.Serialize(graph, headers, binaryWriter, fCheck);
            m_crossAppDomainArray = sow.crossAppDomainArray;
        }
 internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream"));
     }
     this.m_stream = stream;
     this.m_surrogates = selector;
     this.m_context = context;
     this.m_binder = binder;
     if (this.m_binder != null)
     {
         ResourceReader.TypeLimitingDeserializationBinder binder2 = this.m_binder as ResourceReader.TypeLimitingDeserializationBinder;
         if (binder2 != null)
         {
             binder2.ObjectReader = this;
         }
     }
     this.formatterEnums = formatterEnums;
 }
Exemple #19
0
        internal void Serialize(Stream serializationStream, object graph, Header[] headers, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat         = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat     = _assemblyFormat,
            };

            var sow = new ObjectWriter(_surrogates, _context, formatterEnums, _binder);
            BinaryFormatterWriter binaryWriter = new BinaryFormatterWriter(serializationStream, sow, _typeFormat);

            sow.Serialize(graph, headers, binaryWriter, check);
            _crossAppDomainArray = sow._crossAppDomainArray;
        }
Exemple #20
0
 internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream"));
     }
     this.m_stream     = stream;
     this.m_surrogates = selector;
     this.m_context    = context;
     this.m_binder     = binder;
     if (this.m_binder != null)
     {
         ResourceReader.TypeLimitingDeserializationBinder binder2 = this.m_binder as ResourceReader.TypeLimitingDeserializationBinder;
         if (binder2 != null)
         {
             binder2.ObjectReader = this;
         }
     }
     this.formatterEnums = formatterEnums;
 }
 internal object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage)
 {
     if (serializationStream == null)
     {
         throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream }));
     }
     if (serializationStream.CanSeek && (serializationStream.Length == 0L))
     {
         throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));
     }
     InternalFE formatterEnums = new InternalFE {
         FEtypeFormat = this.m_typeFormat,
         FEserializerTypeEnum = InternalSerializerTypeE.Binary,
         FEassemblyFormat = this.m_assemblyFormat,
         FEsecurityLevel = this.m_securityLevel
     };
     ObjectReader objectReader = new ObjectReader(serializationStream, this.m_surrogates, this.m_context, formatterEnums, this.m_binder) {
         crossAppDomainArray = this.m_crossAppDomainArray
     };
     return objectReader.Deserialize(handler, new __BinaryParser(serializationStream, objectReader), fCheck, isCrossAppDomain, methodCallMessage);
 }
Exemple #22
0
        internal object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream }));
            }
            if (serializationStream.CanSeek && (serializationStream.Length == 0L))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));
            }
            InternalFE formatterEnums = new InternalFE {
                FEtypeFormat         = this.m_typeFormat,
                FEserializerTypeEnum = InternalSerializerTypeE.Binary,
                FEassemblyFormat     = this.m_assemblyFormat,
                FEsecurityLevel      = this.m_securityLevel
            };
            ObjectReader objectReader = new ObjectReader(serializationStream, this.m_surrogates, this.m_context, formatterEnums, this.m_binder)
            {
                crossAppDomainArray = this.m_crossAppDomainArray
            };

            return(objectReader.Deserialize(handler, new __BinaryParser(serializationStream, objectReader), fCheck, isCrossAppDomain, methodCallMessage));
        }
Exemple #23
0
        internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
        {
            SerTrace.Log( this, "Constructor ISurrogateSelector ",((selector == null)?"null selector ":"selector present"));                    

            if (stream==null)
            {
                throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream"));
            }

            m_stream=stream;
            m_surrogates = selector;
            m_context = context;
            m_binder =  binder;
            this.formatterEnums = formatterEnums;

            //SerTrace.Log( this, "Constructor formatterEnums.FEtopObject ",formatterEnums.FEtopObject);

        }
 internal void Serialize(Stream serializationStream, object graph, Header[] headers, bool fCheck)
 {
     if (serializationStream == null)
     {
         throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream }));
     }
     InternalFE formatterEnums = new InternalFE {
         FEtypeFormat = this.m_typeFormat,
         FEserializerTypeEnum = InternalSerializerTypeE.Binary,
         FEassemblyFormat = this.m_assemblyFormat
     };
     ObjectWriter objectWriter = new ObjectWriter(this.m_surrogates, this.m_context, formatterEnums, this.m_binder);
     __BinaryWriter serWriter = new __BinaryWriter(serializationStream, objectWriter, this.m_typeFormat);
     objectWriter.Serialize(graph, headers, serWriter, fCheck);
     this.m_crossAppDomainArray = objectWriter.crossAppDomainArray;
 }
Exemple #25
0
        [System.Security.SecurityCritical]  // auto-generated
        internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck)
        {
#if FEATURE_REMOTING        
            return Deserialize(serializationStream, handler, fCheck, null);
#else
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream));
            }
            Contract.EndContractBlock();

            if (serializationStream.CanSeek && (serializationStream.Length == 0))
                throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));

            SerTrace.Log(this, "Deserialize Entry");
            InternalFE formatterEnums = new InternalFE();
            formatterEnums.FEtypeFormat = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat = m_assemblyFormat;
            formatterEnums.FEsecurityLevel = m_securityLevel;

            ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder);
            sor.crossAppDomainArray = m_crossAppDomainArray;
            return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck);

#endif

        }
        internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder)
        {
            if (stream == null) 
            {
                throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); 
            } 
            Contract.EndContractBlock();
 
            SerTrace.Log(this, "Constructor ISurrogateSelector ", ((selector == null) ? "null selector " : "selector present"));

            m_stream=stream;
            m_surrogates = selector; 
            m_context = context;
            m_binder =  binder; 
 
#if !FEATURE_PAL && FEATURE_SERIALIZATION
            // This is a hack to allow us to write a type-limiting deserializer 
            // when we know exactly what type to expect at the head of the
            // object graph.
            if (m_binder != null) {
                ResourceReader.TypeLimitingDeserializationBinder tldBinder = m_binder as ResourceReader.TypeLimitingDeserializationBinder; 
                if (tldBinder != null)
                    tldBinder.ObjectReader = this; 
            } 
#endif // !FEATURE_PAL && FEATURE_SERIALIZATION
 
            this.formatterEnums = formatterEnums;

            //SerTrace.Log( this, "Constructor formatterEnums.FEtopObject ",formatterEnums.FEtopObject);
 
        }
        // Deserialize the stream into an object graph.
        internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) {
            if (serializationStream==null)
            {
                throw new ArgumentNullException("serializationStream", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentNull_WithParamName"),serializationStream));
            }

            if (serializationStream.CanSeek && (serializationStream.Length == 0))
                throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));

            SerTrace.Log(this, "Deserialize Entry");
            InternalFE formatterEnums = new InternalFE();
            formatterEnums.FEtypeFormat = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat = m_assemblyFormat;         
            formatterEnums.FEsecurityLevel = m_securityLevel;    		

    	       ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder);
            sor.crossAppDomainArray = m_crossAppDomainArray;
            return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage);
	}
        // Commences the process of serializing the entire graph.  All of the data (in the appropriate format
        // is emitted onto the stream).
        internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck)
        {
            if (serializationStream==null)
            {
                throw new ArgumentNullException("serializationStream", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentNull_WithParamName"),serializationStream));             
            }
            SerTrace.Log(this, "Serialize Entry");

            InternalFE formatterEnums = new InternalFE();
            formatterEnums.FEtypeFormat = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat = m_assemblyFormat;    

            ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums);
            __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat); 
            sow.Serialize(graph, headers, binaryWriter, fCheck);
            m_crossAppDomainArray = sow.crossAppDomainArray;
        }