FileLoadException.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // System.IO.FileLoadException.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. // Duncan Mak ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc. http://www.ximian.com
  9. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Globalization;
  31. using System.Runtime.Serialization;
  32. using System.Security;
  33. using System.Security.Permissions;
  34. using System.Text;
  35. using System.Runtime.InteropServices;
  36. namespace System.IO {
  37. [Serializable]
  38. [ComVisible (true)]
  39. public class FileLoadException : IOException {
  40. // Fields
  41. const int Result = unchecked ((int)0x80070002);
  42. string msg;
  43. string fileName;
  44. string fusionLog;
  45. // Constructors
  46. public FileLoadException ()
  47. : base (Locale.GetText ("I/O Error"))
  48. {
  49. HResult = Result;
  50. msg = Locale.GetText ("I/O Error");
  51. }
  52. public FileLoadException (string message)
  53. : base (message)
  54. {
  55. HResult = Result;
  56. msg = message;
  57. }
  58. public FileLoadException (string message, string fileName)
  59. : base (message)
  60. {
  61. HResult = Result;
  62. this.msg = message;
  63. this.fileName = fileName;
  64. }
  65. public FileLoadException (string message, Exception inner)
  66. : base (message, inner)
  67. {
  68. HResult = Result;
  69. msg = message;
  70. }
  71. public FileLoadException (string message, string fileName, Exception inner)
  72. : base (message, inner)
  73. {
  74. HResult = Result;
  75. this.msg = message;
  76. this.fileName = fileName;
  77. }
  78. protected FileLoadException (SerializationInfo info, StreamingContext context)
  79. {
  80. fileName = info.GetString ("FileLoad_FileName");
  81. fusionLog = info.GetString ("FileLoad_FusionLog");
  82. }
  83. // Properties
  84. public override string Message {
  85. get { return msg; }
  86. }
  87. public string FileName
  88. {
  89. get { return fileName; }
  90. }
  91. public string FusionLog {
  92. // note: MS runtime throws a SecurityException when the Exception is created
  93. // but a FileLoadException once the exception as been thrown. Mono always
  94. // throw a SecurityException in both case (anyway fusionLog is currently empty)
  95. [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
  96. get { return fusionLog; }
  97. }
  98. // Methods
  99. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  100. {
  101. base.GetObjectData (info, context);
  102. info.AddValue ("FileLoad_FileName", fileName);
  103. info.AddValue ("FileLoad_FusionLog", fusionLog);
  104. }
  105. public override string ToString ()
  106. {
  107. StringBuilder sb = new StringBuilder (GetType ().FullName);
  108. sb.AppendFormat (": {0}", msg);
  109. if (fileName != null)
  110. sb.AppendFormat (" : {0}", fileName);
  111. if (this.InnerException != null)
  112. sb.AppendFormat (" ----> {0}", InnerException);
  113. if (this.StackTrace != null) {
  114. sb.Append (Environment.NewLine);
  115. sb.Append (StackTrace);
  116. }
  117. return sb.ToString ();
  118. }
  119. }
  120. }