Пример #1
0
        private void ReserializeFallback(RemoteNonDeserializableException fallbackException, ISerializationContext outerContext)
        {
            var outerWriter = outerContext.StreamWriter;

            // Write the type name directly.
            var key = new TypeSerializer.TypeKey(fallbackException.OriginalTypeName);

            TypeSerializer.WriteTypeKey(key, outerWriter);

            // Serialize the only accepted fields from the base Exception class.
            var innerContext = new SerializationContext
            {
                StreamWriter = new BinaryTokenStreamWriter()
            };

            this.fallbackBaseExceptionSerializer.Serialize(fallbackException, innerContext, null);

            // Write the length of the serialized exception, then write the serialized bytes.
            var additionalDataLength = fallbackException.AdditionalData?.Length ?? 0;

            outerWriter.Write(innerContext.StreamWriter.CurrentOffset + additionalDataLength);
            outerWriter.Write(innerContext.StreamWriter.ToBytes());

            if (additionalDataLength > 0)
            {
                outerWriter.Write(fallbackException.AdditionalData);
            }
        }
        private void ReserializeFallback(RemoteNonDeserializableException fallbackException, ISerializationContext outerContext)
        {
            var outerWriter = outerContext.StreamWriter;

            // Write the type name directly.
            var key = new TypeSerializer.TypeKey(fallbackException.OriginalTypeName);

            TypeSerializer.WriteTypeKey(key, outerWriter);

            // Create a nested context which will be written to the outer context at an int-length offset from the current position.
            // This is because the inner context will be copied with a length prefix to the outer context.
            var innerContext = outerContext.CreateNestedContext(sizeof(int), new BinaryTokenStreamWriter());

            // Serialize the only accepted fields from the base Exception class.
            this.fallbackBaseExceptionSerializer.Serialize(fallbackException, innerContext, null);

            // Write the length of the serialized exception, then write the serialized bytes.
            var additionalDataLength = fallbackException.AdditionalData?.Length ?? 0;

            outerWriter.Write(innerContext.StreamWriter.CurrentOffset + additionalDataLength);
            outerWriter.Write(innerContext.StreamWriter.ToBytes());

            if (additionalDataLength > 0)
            {
                outerWriter.Write(fallbackException.AdditionalData);
            }
        }