FileLoadException.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 => _message ??= FormatFileLoadExceptionMessage(FileName, HResult);
  38. public string? FileName { get; }
  39. public string? FusionLog { get; }
  40. public override string ToString()
  41. {
  42. string s = GetType().ToString() + ": " + Message;
  43. if (!string.IsNullOrEmpty(FileName))
  44. s += Environment.NewLineConst + SR.Format(SR.IO_FileName_Name, FileName);
  45. if (InnerException != null)
  46. s += Environment.NewLineConst + InnerExceptionPrefix + InnerException.ToString();
  47. if (StackTrace != null)
  48. s += Environment.NewLineConst + StackTrace;
  49. if (FusionLog != null)
  50. {
  51. s ??= " ";
  52. s += Environment.NewLineConst + Environment.NewLineConst + FusionLog;
  53. }
  54. return s;
  55. }
  56. protected FileLoadException(SerializationInfo info, StreamingContext context)
  57. : base(info, context)
  58. {
  59. FileName = info.GetString("FileLoad_FileName");
  60. FusionLog = info.GetString("FileLoad_FusionLog");
  61. }
  62. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  63. {
  64. base.GetObjectData(info, context);
  65. info.AddValue("FileLoad_FileName", FileName, typeof(string));
  66. info.AddValue("FileLoad_FusionLog", FusionLog, typeof(string));
  67. }
  68. }
  69. }