aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs b/src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs
new file mode 100644
index 00000000..b33bf27a
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Msi/MsiException.cs
@@ -0,0 +1,78 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Msi
4{
5 using System;
6 using System.ComponentModel;
7 using WixToolset.Core.Native;
8
9 /// <summary>
10 /// Exception that wraps MsiGetLastError().
11 /// </summary>
12 [Serializable]
13 public class MsiException : Win32Exception
14 {
15 /// <summary>
16 /// Instantiate a new MsiException with a given error.
17 /// </summary>
18 /// <param name="error">The error code from the MsiXxx() function call.</param>
19 public MsiException(int error) : base(error)
20 {
21 uint handle = MsiInterop.MsiGetLastErrorRecord();
22 if (0 != handle)
23 {
24 using (Record record = new Record(handle))
25 {
26 this.MsiError = record.GetInteger(1);
27
28 int errorInfoCount = record.GetFieldCount() - 1;
29 this.ErrorInfo = new string[errorInfoCount];
30 for (int i = 0; i < errorInfoCount; ++i)
31 {
32 this.ErrorInfo[i] = record.GetString(i + 2);
33 }
34 }
35 }
36 else
37 {
38 this.MsiError = 0;
39 this.ErrorInfo = new string[0];
40 }
41
42 this.Error = error;
43 }
44
45 /// <summary>
46 /// Gets the error number.
47 /// </summary>
48 public int Error { get; private set; }
49
50 /// <summary>
51 /// Gets the internal MSI error number.
52 /// </summary>
53 public int MsiError { get; private set; }
54
55 /// <summary>
56 /// Gets any additional the error information.
57 /// </summary>
58 public string[] ErrorInfo { get; private set; }
59
60 /// <summary>
61 /// Overrides Message property to return useful error message.
62 /// </summary>
63 public override string Message
64 {
65 get
66 {
67 if (0 == this.MsiError)
68 {
69 return base.Message;
70 }
71 else
72 {
73 return String.Format("Internal MSI failure. Win32 error: {0}, MSI error: {1}, detail: {2}", this.Error, this.MsiError, String.Join(", ", this.ErrorInfo));
74 }
75 }
76 }
77 }
78}