FileLoadException.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #if NET_2_0
  36. using System.Runtime.InteropServices;
  37. #endif
  38. namespace System.IO {
  39. [Serializable]
  40. #if NET_2_0
  41. [ComVisible (true)]
  42. #endif
  43. public class FileLoadException : IOException {
  44. // Fields
  45. const int Result = unchecked ((int)0x80070002);
  46. string msg;
  47. Exception inner;
  48. string fileName;
  49. string fusionLog;
  50. // Constructors
  51. public FileLoadException ()
  52. : base (Locale.GetText ("I/O Error"))
  53. {
  54. HResult = Result;
  55. msg = Locale.GetText ("I/O Error");
  56. }
  57. public FileLoadException (string message)
  58. : base (message)
  59. {
  60. HResult = Result;
  61. msg = message;
  62. }
  63. public FileLoadException (string message, string fileName)
  64. : base (message)
  65. {
  66. HResult = Result;
  67. this.msg = message;
  68. this.fileName = fileName;
  69. }
  70. public FileLoadException (string message, Exception inner)
  71. : base (message, inner)
  72. {
  73. HResult = Result;
  74. msg = message;
  75. this.inner = inner;
  76. }
  77. public FileLoadException (string message, string fileName, Exception inner)
  78. : base (message, inner)
  79. {
  80. HResult = Result;
  81. this.msg = message;
  82. this.fileName = fileName;
  83. this.inner = inner;
  84. }
  85. protected FileLoadException (SerializationInfo info, StreamingContext context)
  86. {
  87. fileName = info.GetString ("FileLoad_FileName");
  88. fusionLog = info.GetString ("FileLoad_FusionLog");
  89. }
  90. // Properties
  91. public override string Message {
  92. get { return msg; }
  93. }
  94. public string FileName
  95. {
  96. get { return fileName; }
  97. }
  98. public string FusionLog {
  99. // note: MS runtime throws a SecurityException when the Exception is created
  100. // but a FileLoadException once the exception as been thrown. Mono always
  101. // throw a SecurityException in both case (anyway fusionLog is currently empty)
  102. [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
  103. get { return fusionLog; }
  104. }
  105. // Methods
  106. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  107. {
  108. base.GetObjectData (info, context);
  109. info.AddValue ("FileLoad_FileName", fileName);
  110. info.AddValue ("FileLoad_FusionLog", fusionLog);
  111. }
  112. public override string ToString ()
  113. {
  114. StringBuilder sb = new StringBuilder (GetType ().FullName);
  115. sb.AppendFormat (": {0}", msg);
  116. if (fileName != null)
  117. sb.AppendFormat (" : {0}", fileName);
  118. if (this.InnerException != null)
  119. sb.AppendFormat (" ----> {0}", InnerException);
  120. if (this.StackTrace != null) {
  121. sb.Append (Environment.NewLine);
  122. sb.Append (StackTrace);
  123. }
  124. return sb.ToString ();
  125. }
  126. }
  127. }