FileLoadException.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Runtime.Serialization;
  5. namespace System.IO
  6. {
  7. [Serializable]
  8. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  9. public partial class FileLoadException : IOException
  10. {
  11. public FileLoadException()
  12. : base(SR.IO_FileLoad)
  13. {
  14. HResult = HResults.COR_E_FILELOAD;
  15. }
  16. public FileLoadException(string message)
  17. : base(message)
  18. {
  19. HResult = HResults.COR_E_FILELOAD;
  20. }
  21. public FileLoadException(string message, Exception inner)
  22. : base(message, inner)
  23. {
  24. HResult = HResults.COR_E_FILELOAD;
  25. }
  26. public FileLoadException(string message, string fileName) : base(message)
  27. {
  28. HResult = HResults.COR_E_FILELOAD;
  29. FileName = fileName;
  30. }
  31. public FileLoadException(string message, string fileName, Exception inner)
  32. : base(message, inner)
  33. {
  34. HResult = HResults.COR_E_FILELOAD;
  35. FileName = fileName;
  36. }
  37. public override string Message
  38. {
  39. get
  40. {
  41. if (_message == null)
  42. {
  43. _message = FormatFileLoadExceptionMessage(FileName, HResult);
  44. }
  45. return _message;
  46. }
  47. }
  48. public string FileName { get; }
  49. public string FusionLog { get; }
  50. public override string ToString()
  51. {
  52. string s = GetType().ToString() + ": " + Message;
  53. if (FileName != null && FileName.Length != 0)
  54. s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, FileName);
  55. if (InnerException != null)
  56. s = s + " ---> " + InnerException.ToString();
  57. if (StackTrace != null)
  58. s += Environment.NewLine + StackTrace;
  59. if (FusionLog != null)
  60. {
  61. if (s == null)
  62. s = " ";
  63. s += Environment.NewLine;
  64. s += Environment.NewLine;
  65. s += FusionLog;
  66. }
  67. return s;
  68. }
  69. protected FileLoadException(SerializationInfo info, StreamingContext context)
  70. : base(info, context)
  71. {
  72. FileName = info.GetString("FileLoad_FileName");
  73. FusionLog = info.GetString("FileLoad_FusionLog");
  74. }
  75. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  76. {
  77. base.GetObjectData(info, context);
  78. info.AddValue("FileLoad_FileName", FileName, typeof(string));
  79. info.AddValue("FileLoad_FusionLog", FusionLog, typeof(string));
  80. }
  81. }
  82. }