Ejemplo n.º 1
0
        private static bool TryDeserializeExceptionData(string exceptionString, out ServiceExceptionData result)
        {
            try
            {
                var stringReader = new StringReader(exceptionString);

                // disabling DTD processing on XML streams that are not over the network.
                var settings = new XmlReaderSettings
                {
                    DtdProcessing = DtdProcessing.Prohibit,
                    XmlResolver   = null
                };
                using (var textStream = XmlReader.Create(stringReader, settings))
                {
                    result = (ServiceExceptionData)serializer.ReadObject(textStream);
                    return(true);
                }
            }
            catch (Exception)
            {
                // no-op
            }

            result = null;
            return(false);
        }
Ejemplo n.º 2
0
        private static bool TryDeserializeExceptionData(byte[] data, out ServiceExceptionData result)
        {
            try
            {
                var exceptionData = (ServiceExceptionData)SerializationUtility.Deserialize(serializer, data);
                result = exceptionData;
                return(true);
            }
            catch (Exception)
            {
                // no-op
            }

            result = null;
            return(false);
        }
Ejemplo n.º 3
0
        private static bool TryDeserializeExceptionData(byte[] data, out ServiceExceptionData result)
        {
            try
            {
                var exceptionData = (ServiceExceptionData)SerializationUtility.Deserialize(serializer, data);
                result = exceptionData;
                return(true);
            }
            catch (Exception e)
            {
                //swallowing the exception
                ServiceTrace.Source.WriteWarning("RemoteExceptionInformation", " ServiceExceptionData DeSerialization failed : Reason  {0}", e);
            }

            result = null;
            return(false);
        }
        private static byte[] SerializeServiceExceptionData(ServiceExceptionData msg)
        {
            if (msg == null)
            {
                return(null);
            }

            using (var stream = new MemoryStream())
            {
                using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
                {
                    serviceExceptionDataSerializer.WriteObject(writer, msg);
                    writer.Flush();
                    return(stream.ToArray());
                }
            }
        }
        internal static bool TryDeserializeExceptionData(Stream data, out ServiceExceptionData result)
        {
            try
            {
                var exceptionData = (ServiceExceptionData)DeserializeServiceExceptionData(data);
                result = exceptionData;
                return(true);
            }
            catch (Exception e)
            {
                //swallowing the exception
                ServiceTrace.Source.WriteWarning("RemoteException",
                                                 " ServiceExceptionData DeSerialization failed : Reason  {0}", e);
            }

            result = null;
            return(false);
        }
Ejemplo n.º 6
0
        public static string ToString(Exception exception)
        {
            try
            {
                var serializer = new NetDataContractSerializer();

                var stringWriter = new StringWriter();

                using (var textStream = XmlWriter.Create(stringWriter))
                {
                    serializer.WriteObject(textStream, exception);
                    textStream.Flush();

                    return(stringWriter.ToString());
                }
            }
            catch (Exception e)
            {
                var exceptionStringBuilder = new StringBuilder();

                exceptionStringBuilder.AppendFormat(
                    CultureInfo.CurrentCulture,
                    Microsoft.ServiceFabric.Services.Wcf.SR.ErrorExceptionSerializationFailed1,
                    exception.GetType().FullName);

                exceptionStringBuilder.AppendLine();

                exceptionStringBuilder.AppendFormat(
                    CultureInfo.CurrentCulture,
                    Microsoft.ServiceFabric.Services.Wcf.SR.ErrorExceptionSerializationFailed2,
                    exception);

                var exceptionData = new ServiceExceptionData(exception.GetType().FullName,
                                                             exceptionStringBuilder.ToString());
                string result;
                if (TrySerializeExceptionData(exceptionData, out result))
                {
                    return(result);
                }
                throw e;
            }
        }
Ejemplo n.º 7
0
        private static RemoteExceptionInformation FromExceptionString(Exception exception)
        {
            var exceptionStringBuilder = new StringBuilder();

            exceptionStringBuilder.AppendFormat(
                CultureInfo.CurrentCulture,
                SR.ErrorExceptionSerializationFailed1,
                exception.GetType().FullName);

            exceptionStringBuilder.AppendLine();

            exceptionStringBuilder.AppendFormat(
                CultureInfo.CurrentCulture,
                SR.ErrorExceptionSerializationFailed2,
                exception);
            var exceptionData = new ServiceExceptionData(exception.GetType().FullName, exceptionStringBuilder.ToString());

            var exceptionBytes = SerializationUtility.Serialize(serializer, exceptionData);

            return(new RemoteExceptionInformation(exceptionBytes));
        }
        internal static List <ArraySegment <byte> > FromExceptionString(Exception exception)
        {
            var exceptionStringBuilder = new StringBuilder();

            exceptionStringBuilder.AppendFormat(
                CultureInfo.CurrentCulture,
                SR.ErrorExceptionSerializationFailed1,
                exception.GetType().FullName);

            exceptionStringBuilder.AppendLine();

            exceptionStringBuilder.AppendFormat(
                CultureInfo.CurrentCulture,
                SR.ErrorExceptionSerializationFailed2,
                exception);
            var exceptionData = new ServiceExceptionData(exception.GetType().FullName, exceptionStringBuilder.ToString());

            var exceptionBytes = SerializeServiceExceptionData(exceptionData);
            var buffers        = new List <ArraySegment <byte> >();

            buffers.Add(new ArraySegment <byte>(exceptionBytes));
            return(buffers);
        }
Ejemplo n.º 9
0
        private static bool TrySerializeExceptionData(ServiceExceptionData serviceExceptionData, out string result)
        {
            try
            {
                var stringWriter = new StringWriter();

                using (var textStream = XmlWriter.Create(stringWriter))
                {
                    serializer.WriteObject(textStream, serviceExceptionData);
                    textStream.Flush();

                    result = stringWriter.ToString();
                    return(true);

                    ;
                }
            }
            catch (Exception)
            {
                // no-op
            }
            result = null;
            return(false);
        }