public int v3() { Exception inner = new Exception(); XmlException e = new XmlException("error", inner, 14, 36); CompareException(e, "Xml_UserException", inner, 14, 36); return TEST_PASS; }
public void Update(Result result) { if (result == null) throw new ArgumentNullException("result"); this.state = result.State; if (result.Exception != null) this.exception = XmlException.FromException(result.Exception); this.Update(result.Monitor); }
protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition) { string actualCode = expectedCode; CError.WriteLine("***Exception"); CError.WriteLineIgnore(e.ToString()); CError.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber"); CError.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition"); CError.Compare(actualCode, expectedCode, "ec" + e.Message); }
private void CompareException(XmlException e, string ec, Exception inner, int ln, int lp) { CError.WriteLine(e); CError.Compare((object)e.InnerException, (object)inner, "InnerException"); CError.Compare(e.LineNumber, ln, "LineNumber"); CError.Compare(e.LinePosition, lp, "LinePosition"); string s1 = e.StackTrace; Type t = e.GetType(); Exception e2 = e.GetBaseException(); int i = e.GetHashCode(); CError.Compare(!String.IsNullOrEmpty(e.Message), "Message"); string s3 = e.ToString(); }
private object GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver) { object obj2 = null; string mimeType = dataNodeInfo.MimeType; string typeName = ((dataNodeInfo.TypeName == null) || (dataNodeInfo.TypeName.Length == 0)) ? MultitargetUtil.GetAssemblyQualifiedName(typeof(string), this.typeNameConverter) : dataNodeInfo.TypeName; if ((mimeType != null) && (mimeType.Length > 0)) { if ((string.Equals(mimeType, ResXResourceWriter.BinSerializedObjectMimeType) || string.Equals(mimeType, ResXResourceWriter.Beta2CompatSerializedObjectMimeType)) || string.Equals(mimeType, ResXResourceWriter.CompatBinSerializedObjectMimeType)) { byte[] buffer = FromBase64WrappedString(dataNodeInfo.ValueData); if (this.binaryFormatter == null) { this.binaryFormatter = new BinaryFormatter(); this.binaryFormatter.Binder = new ResXSerializationBinder(typeResolver); } IFormatter binaryFormatter = this.binaryFormatter; if ((buffer != null) && (buffer.Length > 0)) { obj2 = binaryFormatter.Deserialize(new MemoryStream(buffer)); if (obj2 is ResXNullRef) { obj2 = null; } } return(obj2); } if (string.Equals(mimeType, ResXResourceWriter.SoapSerializedObjectMimeType) || string.Equals(mimeType, ResXResourceWriter.CompatSoapSerializedObjectMimeType)) { byte[] buffer2 = FromBase64WrappedString(dataNodeInfo.ValueData); if ((buffer2 != null) && (buffer2.Length > 0)) { obj2 = this.CreateSoapFormatter().Deserialize(new MemoryStream(buffer2)); if (obj2 is ResXNullRef) { obj2 = null; } } return(obj2); } if ((!string.Equals(mimeType, ResXResourceWriter.ByteArraySerializedObjectMimeType) || (typeName == null)) || (typeName.Length <= 0)) { return(obj2); } System.Type type = this.ResolveType(typeName, typeResolver); if (type != null) { TypeConverter converter = TypeDescriptor.GetConverter(type); if (converter.CanConvertFrom(typeof(byte[]))) { byte[] buffer3 = FromBase64WrappedString(dataNodeInfo.ValueData); if (buffer3 != null) { obj2 = converter.ConvertFrom(buffer3); } } return(obj2); } string str6 = System.Windows.Forms.SR.GetString("TypeLoadException", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X }); XmlException exception = new XmlException(str6, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException exception2 = new TypeLoadException(str6, exception); throw exception2; } if ((typeName == null) || (typeName.Length <= 0)) { return(obj2); } System.Type type2 = this.ResolveType(typeName, typeResolver); if (type2 != null) { if (type2 == typeof(ResXNullRef)) { return(null); } if ((typeName.IndexOf("System.Byte[]") != -1) && (typeName.IndexOf("mscorlib") != -1)) { return(FromBase64WrappedString(dataNodeInfo.ValueData)); } TypeConverter converter2 = TypeDescriptor.GetConverter(type2); if (!converter2.CanConvertFrom(typeof(string))) { return(obj2); } string valueData = dataNodeInfo.ValueData; try { return(converter2.ConvertFromInvariantString(valueData)); } catch (NotSupportedException exception3) { string str8 = System.Windows.Forms.SR.GetString("NotSupported", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X, exception3.Message }); XmlException innerException = new XmlException(str8, exception3, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); NotSupportedException exception5 = new NotSupportedException(str8, innerException); throw exception5; } } string message = System.Windows.Forms.SR.GetString("TypeLoadException", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X }); XmlException inner = new XmlException(message, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException exception7 = new TypeLoadException(message, inner); throw exception7; }
public XmlLogEntry(Exception ex) { this.level = LogLevel.Error; this.message = ex.Message; this.exception = XmlException.FromException(ex); }
/// <summary> /// Adds an error to the list. /// </summary> public void AddError(string fileName, XmlException ex) { SetupDialogErrorListViewItem errorItem = new SetupDialogErrorListViewItem(fileName, ex); Items.Add(errorItem); }
public MalformedXmlException(XmlException ex) : base(ErrorCode.rsMalformedXml, ErrorStrings.rsMalformedXml(ex.Message), ex, null) { }
private void LoadData() { hasht = new OrderedDictionary(); hashtm = new OrderedDictionary(); if (fileName != null) { stream = File.OpenRead(fileName); } try { xmlReader = null; if (stream != null) { xmlReader = new XmlTextReader(stream); } else if (reader != null) { xmlReader = new XmlTextReader(reader); } if (xmlReader == null) { throw new InvalidOperationException("ResourceReader is closed."); } xmlReader.WhitespaceHandling = WhitespaceHandling.None; ResXHeader header = new ResXHeader(); try { while (xmlReader.Read()) { if (xmlReader.NodeType != XmlNodeType.Element) { continue; } switch (xmlReader.LocalName) { case "resheader": ParseHeaderNode(header); break; case "data": ParseDataNode(false); break; case "metadata": ParseDataNode(true); break; } } } catch (XmlException ex) { throw new ArgumentException("Invalid ResX input.", ex); } catch (SerializationException ex) { throw ex; } catch (TargetInvocationException ex) { throw ex; } catch (Exception ex) { XmlException xex = new XmlException(ex.Message, ex, xmlReader.LineNumber, xmlReader.LinePosition); throw new ArgumentException("Invalid ResX input.", xex); } header.Verify(); } finally { if (fileName != null) { stream.Close(); stream = null; } xmlReader = null; } }
/// <summary> /// Adds a detected validation exception. /// </summary> /// <param name="e">The exception.</param> protected virtual void AddValidationException(XmlException e) { validationExceptions.Add(e); }
/// <summary> /// Constructor from an XML exception /// </summary> /// <param name="exception">The exception.</param> public CCPAPIResult(XmlException exception) : this((Exception)exception) { m_error = APIErrorType.Xml; }
/// <summary> /// Instantiate a new WixSchemaValidationException. /// </summary> /// <param name="sourceLineNumbers">Source line information of the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception.</param> public WixInvalidXmlException(SourceLineNumberCollection sourceLineNumbers, XmlException innerException) : base(sourceLineNumbers, WixExceptionType.InvalidXml, innerException) { }
void AddToErrorList(XmlException ex) { TaskService.ClearExceptCommentTasks(); TaskService.Add(new Task(this.PrimaryFileName, ex.Message, ex.LinePosition - 1, ex.LineNumber - 1, TaskType.Error)); WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront(); }
public static ParseException ToParseException(this XmlException exception, string format) { return(new ParseException(exception, format, exception.LineNumber, exception.LinePosition)); }
public void Warning(XmlException exception) { System.Diagnostics.Debug.WriteLine(exception); }
public void Error(XmlException exception) { System.Diagnostics.Debug.WriteLine(exception); }
public static void XmlException(XmlException ex) { WriteGenericLog(ex); logManager.Write("Line Number:" + ex.LineNumber.ToString()); logManager.Write("Line Position:" + ex.LinePosition.ToString()); }
private void ParseXml(XmlTextReader reader) { bool success = false; try { try { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string s = reader.LocalName; if (reader.LocalName.Equals(ResXResourceWriter.AssemblyStr)) { ParseAssemblyNode(reader); } else if (reader.LocalName.Equals(ResXResourceWriter.DataStr)) { ParseDataNode(reader, false); } else if (reader.LocalName.Equals(ResXResourceWriter.MetadataStr)) { ParseDataNode(reader, true); } } } success = true; } catch (SerializationException se) { Point pt = GetPosition(reader); string newMessage = string.Format( SR.SerializationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, se.Message); XmlException xml = new XmlException(newMessage, se, pt.Y, pt.X); SerializationException newSe = new SerializationException(newMessage, xml); throw newSe; } catch (TargetInvocationException tie) { Point pt = GetPosition(reader); string newMessage = string.Format( SR.InvocationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, tie.InnerException.Message); XmlException xml = new XmlException(newMessage, tie.InnerException, pt.Y, pt.X); TargetInvocationException newTie = new TargetInvocationException(newMessage, xml); throw newTie; } catch (XmlException e) { throw new ArgumentException(string.Format(SR.InvalidResXFile, e.Message), e); } catch (Exception e) { if (ClientUtils.IsSecurityOrCriticalException(e)) { throw; } else { Point pt = GetPosition(reader); XmlException xmlEx = new XmlException(e.Message, e, pt.Y, pt.X); throw new ArgumentException(string.Format(SR.InvalidResXFile, xmlEx.Message), xmlEx); } } } finally { if (!success) { resData = null; resMetadata = null; } } }
internal static IActionResult XmlFormatMismathErrorResult(this MemcachedController controller, string key, XmlException ex, ILogger logger) { var error = new { error = "Format Mismatch", description = "Value in key:[" + key + "] is not xml." }; logger.LogDebug(ex, "Error : " + JsonConvert.SerializeObject(error)); return(controller.StatusCode(StatusCodes.Status400BadRequest, error)); }
protected override Message DecodeMessage(byte[] buffer, ref int offset, ref int size, ref bool isAtEOF, TimeSpan timeout) { while (size > 0) { int num = this.decoder.Decode(buffer, offset, size); if (num > 0) { if (base.EnvelopeBuffer != null) { if (!object.ReferenceEquals(buffer, base.EnvelopeBuffer)) { Buffer.BlockCopy(buffer, offset, base.EnvelopeBuffer, base.EnvelopeOffset, num); } Microsoft.ServiceBus.Channels.ClientDuplexConnectionReader envelopeOffset = this; envelopeOffset.EnvelopeOffset = envelopeOffset.EnvelopeOffset + num; } offset = offset + num; size = size - num; } Microsoft.ServiceBus.Channels.ClientFramingDecoderState currentState = this.decoder.CurrentState; if (currentState == Microsoft.ServiceBus.Channels.ClientFramingDecoderState.Fault) { this.channel.Session.CloseOutputSession(((IDefaultCommunicationTimeouts)this.channel).CloseTimeout); throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.FaultStringDecoder.GetFaultException(this.decoder.Fault, this.channel.RemoteAddress.Uri.AbsoluteUri, this.messageEncoder.ContentType)); } switch (currentState) { case Microsoft.ServiceBus.Channels.ClientFramingDecoderState.EnvelopeStart: { int envelopeSize = this.decoder.EnvelopeSize; if (envelopeSize > this.maxBufferSize) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.MaxMessageSizeStream.CreateMaxReceivedMessageSizeExceededException((long)this.maxBufferSize)); } base.EnvelopeBuffer = this.bufferManager.TakeBuffer(envelopeSize); base.EnvelopeOffset = 0; base.EnvelopeSize = envelopeSize; continue; } case Microsoft.ServiceBus.Channels.ClientFramingDecoderState.EnvelopeEnd: { if (base.EnvelopeBuffer == null) { continue; } Message message = null; try { using (IDisposable disposable = Microsoft.ServiceBus.Channels.ClientDuplexConnectionReader.CreateProcessActionActivity()) { message = this.messageEncoder.ReadMessage(new ArraySegment <byte>(base.EnvelopeBuffer, 0, base.EnvelopeSize), this.bufferManager); } } catch (XmlException xmlException1) { XmlException xmlException = xmlException1; throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(Resources.MessageXmlProtocolError, new object[0]), xmlException)); } base.EnvelopeBuffer = null; return(message); } case Microsoft.ServiceBus.Channels.ClientFramingDecoderState.End: { isAtEOF = true; return(null); } default: { continue; } } } return(null); }
public void ShowXmlIsNotWellFormedMessage(XmlException ex) { notWellFormedMessageDisplayed = true; notWellFormedException = ex; }
private object GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver) { object result = null; string mimeTypeName = dataNodeInfo.MimeType; // default behavior: if we dont have a type name, it's a string string typeName = string.IsNullOrEmpty(dataNodeInfo.TypeName) ? MultitargetUtil.GetAssemblyQualifiedName(typeof(string), _typeNameConverter) : dataNodeInfo.TypeName; if (!string.IsNullOrEmpty(mimeTypeName)) { if (string.Equals(mimeTypeName, ResXResourceWriter.BinSerializedObjectMimeType)) { string text = dataNodeInfo.ValueData; byte[] serializedData = FromBase64WrappedString(text); if (_binaryFormatter is null) { _binaryFormatter = new BinaryFormatter { Binder = new ResXSerializationBinder(typeResolver) }; } IFormatter formatter = _binaryFormatter; if (serializedData != null && serializedData.Length > 0) { #pragma warning disable CS0618, SYSLIB0011 // Type or member is obsolete result = formatter.Deserialize(new MemoryStream(serializedData)); #pragma warning restore CS0618, SYSLIB0011 // Type or member is obsolete if (result is ResXNullRef) { result = null; } } } else if (string.Equals(mimeTypeName, ResXResourceWriter.ByteArraySerializedObjectMimeType)) { if (!string.IsNullOrEmpty(typeName)) { Type type = ResolveType(typeName, typeResolver); if (type != null) { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc.CanConvertFrom(typeof(byte[]))) { string text = dataNodeInfo.ValueData; byte[] serializedData = FromBase64WrappedString(text); if (serializedData != null) { result = tc.ConvertFrom(serializedData); } } } else { string newMessage = string.Format(SR.TypeLoadException, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); XmlException xml = new XmlException(newMessage, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException newTle = new TypeLoadException(newMessage, xml); throw newTle; } } } } else if (!string.IsNullOrEmpty(typeName)) { Type type = ResolveType(typeName, typeResolver); if (type != null) { if (type == typeof(ResXNullRef)) { result = null; } else if (typeName.IndexOf("System.Byte[]") != -1 && typeName.IndexOf("mscorlib") != -1) { // Handle byte[]'s, which are stored as base-64 encoded strings. // We can't hard-code byte[] type name due to version number // updates & potential whitespace issues with ResX files. result = FromBase64WrappedString(dataNodeInfo.ValueData); } else { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc.CanConvertFrom(typeof(string))) { string text = dataNodeInfo.ValueData; try { result = tc.ConvertFromInvariantString(text); } catch (NotSupportedException nse) { string newMessage = string.Format(SR.NotSupported, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X, nse.Message); XmlException xml = new XmlException(newMessage, nse, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); NotSupportedException newNse = new NotSupportedException(newMessage, xml); throw newNse; } } else { Debug.WriteLine("Converter for " + type.FullName + " doesn't support string conversion"); } } } else { string newMessage = string.Format(SR.TypeLoadException, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); XmlException xml = new XmlException(newMessage, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException newTle = new TypeLoadException(newMessage, xml); throw newTle; } } else { // if mimeTypeName and typeName are not filled in, the value must be a string Debug.Assert(_value is string, "Resource entries with no Type or MimeType must be encoded as strings"); } return(result); }
public DeserializeJSonException(XmlException xmlException, string jsonString) : base("Error deserializing JSON string", xmlException) { JsonString = jsonString; }
/// <summary> /// Constructor from an XML exception /// </summary> public APIResult(XmlException exc) { m_error = APIErrors.Xml; m_errorMessage = exc.Message; }
//Methods public void TestXmlExceptionEmptyConstructor() { XmlException x = new XmlException(); AssertNotNull(x.Message); }
public void ShowXmlIsNotWellFormedMessage(XmlException ex) { ShowErrorMessage(ex.Message); }
protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition);
/// <summary> /// Creates an instance of this class using the information in the given XmlException and file location. /// </summary> internal BuildEventFileInfo(string file, XmlException e) : this(e) { ErrorUtilities.VerifyThrowArgumentNull(file, nameof(file)); _file = file; }
public SetupDialogErrorListViewItem(string fileName, XmlException ex) : this(fileName, ex.LineNumber, ex.LinePosition) { }
public void TestXmlExceptionStringConstructor() { XmlException x = new XmlException("foo_for_the_masses"); AssertEquals(x.Message,"foo_for_the_masses"); }
public int v1() { XmlException e = new XmlException("error"); CompareException(e, "Xml_UserException", null, 0, 0); return TEST_PASS; }
private static void ProcessFile(String inFile, String outFile, ResourceClassOptions resourceClassOptions, bool useSourcePath) { //Console.WriteLine("Processing {0} --> {1}", inFile, outFile); // Reset state resources.Clear(); resourcesHashTable.Clear(); try { // Explicitly handle missing input files here - don't catch a // FileNotFoundException since we can get them from the loader // if we try loading an assembly version we can't find. if (!File.Exists(inFile)) { Error(SR.GetString(SR.FileNotFound, inFile)); return; } ReadResources(inFile, useSourcePath); } catch (ArgumentException ae) { if (ae.InnerException is XmlException) { XmlException xe = (XmlException)ae.InnerException; Error(xe.Message, inFile, xe.LineNumber, xe.LinePosition); } else { Error(ae.Message, inFile); } return; } catch (TextFileException tfe) { // Used to pass back error context from ReadTextResources to here. Error(tfe.Message, tfe.FileName, tfe.LineNumber, tfe.LinePosition); return; } catch (Exception e) { Error(e.Message, inFile); // We need to give meaningful error messages to the user. // Note that ResXResourceReader wraps any exception it gets // in an ArgumentException with the message "Invalid ResX input." // If you don't look at the InnerException, you have to attach // a debugger to find the problem. if (e.InnerException != null) { Exception inner = e.InnerException; StringBuilder sb = new StringBuilder(200); sb.Append(e.Message); while (inner != null) { sb.Append(" ---> "); sb.Append(inner.GetType().Name); sb.Append(": "); sb.Append(inner.Message); inner = inner.InnerException; } Error(SR.GetString(SR.SpecificError, e.InnerException.GetType().Name, sb.ToString()), inFile); } return; } try { WriteResources(outFile); } catch (IOException io) { Error(SR.GetString(SR.WriteError, outFile), outFile); if (io.Message != null) { Error(SR.GetString(SR.SpecificError, io.GetType().Name, io.Message), outFile); } if (File.Exists(outFile)) { Error(SR.GetString(SR.CorruptOutput, outFile)); try { File.Delete(outFile); } catch (Exception) { Error(SR.GetString(SR.DeleteOutputFileFailed, outFile)); } } return; } catch (Exception e) { Error(SR.GetString(SR.GenericWriteError, outFile)); if (e.Message != null) { Error(SR.GetString(SR.SpecificError, e.GetType().Name, e.Message)); } } }
public ErrorInfo(string fileName, XmlException error) { FileName = fileName; Error = error; }
public int v0() { XmlException e = new XmlException(); CompareException(e, "Xml_DefaultException", null, 0, 0); return TEST_PASS; }
/// <summary> /// Handle the import event arguments changing. /// </summary> /// <param name="sender">The import report whose ImportEventArgs changed.</param> /// <param name="eventArgs">The event arguments.</param> private static void OnImportEventArgsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs) { DataImporter.ImportEventArgs importEventArgs = eventArgs.NewValue as DataImporter.ImportEventArgs; String fullText = ""; String error = ""; sender.SetValue(WindowImportReport.FailedProperty, importEventArgs.Exception != null); sender.SetValue(WindowImportReport.FailedCountProperty, importEventArgs.FailedCount); sender.SetValue(WindowImportReport.SucceededCountProperty, importEventArgs.SucceededCount); if (importEventArgs.Exception == null) { fullText = String.Format(Properties.Resources.ImportSucceededWithErrors, importEventArgs.SucceededCount, importEventArgs.FailedCount); } else { if (importEventArgs.Exception is ThreadAbortException) { error = String.Format(Properties.Resources.ImportAborted, importEventArgs.SucceededCount); } else if (importEventArgs.Exception is ImportHeaderNotFoundException) { StringBuilder headerText = new StringBuilder(); ICollection <String> headers = (importEventArgs.Exception as ImportHeaderNotFoundException).Headers; ICollection <String> missingHeaders = (importEventArgs.Exception as ImportHeaderNotFoundException).MissingHeaders; Int32 index = 0; if (missingHeaders != null) { foreach (String header in missingHeaders) { index += 1; headerText.Append(header); if (index < missingHeaders.Count) { headerText.Append(", "); } } error = String.Format(Properties.Resources.ImportFailedRequiredColumnMissing, headerText); } else { foreach (String header in headers) { index += 1; headerText.Append(header); if (index < headers.Count) { headerText.Append(", "); } } error = String.Format(Properties.Resources.ImportFailedNoHeaders, headerText); } } else if (importEventArgs.Exception is XmlSchemaValidationException) { XmlSchemaValidationException exception = importEventArgs.Exception as XmlSchemaValidationException; error = String.Format(Properties.Resources.XmlValidationFailed, exception.LineNumber, exception.LinePosition, exception.Message); } else if (importEventArgs.Exception is XmlException) { XmlException exception = importEventArgs.Exception as XmlException; error = String.Format(Properties.Resources.XmlValidationFailed, exception.LineNumber, exception.LinePosition, exception.Message); } else if (importEventArgs.Exception is FormatException) { XmlException exception = importEventArgs.Exception as XmlException; error = String.Format(Properties.Resources.ImportVersionMismatch, sender.GetValue(WindowImportReport.SchemaVersionProperty)); } else { error = importEventArgs.Exception.Message; // This is an unexpected error. Log it. FluidTrade.Core.EventLog.Error("Exception while importing: {0}\nStack trace: {1}", importEventArgs.Exception.Message, importEventArgs.Exception.StackTrace); } fullText = String.Format(Properties.Resources.ImportFailed, error); } sender.SetValue(WindowImportReport.ErrorProperty, fullText); }
private void ParseXml(XmlTextReader reader) { bool success = false; try { try { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string s = reader.LocalName; if (reader.LocalName.Equals(ResXResourceWriter.AssemblyStr)) { ParseAssemblyNode(reader); } else if (reader.LocalName.Equals(ResXResourceWriter.DataStr)) { ParseDataNode(reader, false); } else if (reader.LocalName.Equals(ResXResourceWriter.ResHeaderStr)) { ParseResHeaderNode(reader); } else if (reader.LocalName.Equals(ResXResourceWriter.MetadataStr)) { ParseDataNode(reader, true); } } } success = true; } catch (SerializationException se) { Point pt = GetPosition(reader); string newMessage = string.Format(SR.SerializationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, se.Message); XmlException xml = new XmlException(newMessage, se, pt.Y, pt.X); SerializationException newSe = new SerializationException(newMessage, xml); throw newSe; } catch (TargetInvocationException tie) { Point pt = GetPosition(reader); string newMessage = string.Format(SR.InvocationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, tie.InnerException.Message); XmlException xml = new XmlException(newMessage, tie.InnerException, pt.Y, pt.X); TargetInvocationException newTie = new TargetInvocationException(newMessage, xml); throw newTie; } catch (XmlException e) { throw new ArgumentException(string.Format(SR.InvalidResXFile, e.Message), e); } catch (Exception e) { if (ClientUtils.IsCriticalException(e)) { throw; } else { Point pt = GetPosition(reader); XmlException xmlEx = new XmlException(e.Message, e, pt.Y, pt.X); throw new ArgumentException(string.Format(SR.InvalidResXFile, xmlEx.Message), xmlEx); } } } finally { if (!success) { _resData = null; _resMetadata = null; } } bool validFile = false; if (_resHeaderMimeType == ResXResourceWriter.ResMimeType) { Type readerType = typeof(ResXResourceReader); Type writerType = typeof(ResXResourceWriter); string readerTypeName = _resHeaderReaderType; string writerTypeName = _resHeaderWriterType; if (readerTypeName != null && readerTypeName.IndexOf(',') != -1) { readerTypeName = readerTypeName.Split(',')[0].Trim(); } if (writerTypeName != null && writerTypeName.IndexOf(',') != -1) { writerTypeName = writerTypeName.Split(',')[0].Trim(); } if (readerTypeName != null && writerTypeName != null && readerTypeName.Equals(readerType.FullName) && writerTypeName.Equals(writerType.FullName)) { validFile = true; } } if (!validFile) { _resData = null; _resMetadata = null; throw new ArgumentException(SR.InvalidResXFileReaderWriterTypes); } }
private static void ReportExceptionForETW(XmlException exception) { PSEtwLog.LogAnalyticError(PSEventId.Serializer_XmlExceptionWhenDeserializing, PSOpcode.Exception, PSTask.Serialization, PSKeyword.Serializer | PSKeyword.UseAlwaysAnalytic, new object[] { exception.LineNumber, exception.LinePosition, exception.ToString() }); }
public int XmlExceptionCtorWithNoParamsDoesNotThrow() { try { XmlException e = new XmlException(); } catch (XmlException e) { CError.WriteLine(e.Message); return TEST_FAIL; } return TEST_PASS; }
private object GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver) { object result = null; string mimeTypeName = dataNodeInfo.MimeType; // default behavior: if we dont have a type name, it's a string string typeName = (dataNodeInfo.TypeName == null || dataNodeInfo.TypeName.Length == 0 ? MultitargetUtil.GetAssemblyQualifiedName(typeof(string), this.typeNameConverter) : dataNodeInfo.TypeName); if (mimeTypeName != null && mimeTypeName.Length > 0) { if (String.Equals(mimeTypeName, ResXResourceWriter.BinSerializedObjectMimeType) || String.Equals(mimeTypeName, ResXResourceWriter.Beta2CompatSerializedObjectMimeType) || String.Equals(mimeTypeName, ResXResourceWriter.CompatBinSerializedObjectMimeType)) { string text = dataNodeInfo.ValueData; byte[] serializedData; serializedData = FromBase64WrappedString(text); if (binaryFormatter == null) { binaryFormatter = new BinaryFormatter(); binaryFormatter.Binder = new ResXSerializationBinder(typeResolver); } IFormatter formatter = binaryFormatter; if (serializedData != null && serializedData.Length > 0) { result = formatter.Deserialize(new MemoryStream(serializedData)); if (result is ResXNullRef) { result = null; } } } #if SOAP_FORMATTER else if (String.Equals(mimeTypeName, ResXResourceWriter.SoapSerializedObjectMimeType) || String.Equals(mimeTypeName, ResXResourceWriter.CompatSoapSerializedObjectMimeType)) { string text = dataNodeInfo.ValueData; byte[] serializedData; serializedData = FromBase64WrappedString(text); if (serializedData != null && serializedData.Length > 0) { // Performance : don't inline a new SoapFormatter here. That will always bring in // the soap assembly, which we don't want. Throw this in another // function so the class doesn't have to get loaded. // IFormatter formatter = CreateSoapFormatter(); result = formatter.Deserialize(new MemoryStream(serializedData)); if (result is ResXNullRef) { result = null; } } } #endif else if (String.Equals(mimeTypeName, ResXResourceWriter.ByteArraySerializedObjectMimeType)) { if (typeName != null && typeName.Length > 0) { Type type = ResolveType(typeName, typeResolver); if (type != null) { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc.CanConvertFrom(typeof(byte[]))) { string text = dataNodeInfo.ValueData; byte[] serializedData; serializedData = FromBase64WrappedString(text); if (serializedData != null) { result = tc.ConvertFrom(serializedData); } } } else { string newMessage = string.Format(SR.TypeLoadException, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); XmlException xml = new XmlException(newMessage, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException newTle = new TypeLoadException(newMessage, xml); throw newTle; } } } } else if (typeName != null && typeName.Length > 0) { Type type = ResolveType(typeName, typeResolver); if (type != null) { if (type == typeof(ResXNullRef)) { result = null; } else if (typeName.IndexOf("System.Byte[]") != -1 && typeName.IndexOf("mscorlib") != -1) { // Handle byte[]'s, which are stored as base-64 encoded strings. // We can't hard-code byte[] type name due to version number // updates & potential whitespace issues with ResX files. result = FromBase64WrappedString(dataNodeInfo.ValueData); } else { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc.CanConvertFrom(typeof(string))) { string text = dataNodeInfo.ValueData; try { result = tc.ConvertFromInvariantString(text); } catch (NotSupportedException nse) { string newMessage = string.Format(SR.NotSupported, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X, nse.Message); XmlException xml = new XmlException(newMessage, nse, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); NotSupportedException newNse = new NotSupportedException(newMessage, xml); throw newNse; } } else { Debug.WriteLine("Converter for " + type.FullName + " doesn't support string conversion"); } } } else { string newMessage = string.Format(SR.TypeLoadException, typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); XmlException xml = new XmlException(newMessage, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X); TypeLoadException newTle = new TypeLoadException(newMessage, xml); throw newTle; } } else { // if mimeTypeName and typeName are not filled in, the value must be a string Debug.Assert(value is string, "Resource entries with no Type or MimeType must be encoded as strings"); } return(result); }