CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DataPortalException.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortalException.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This exception is returned for any errors occuring</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Security.Permissions;
11
12namespace Csla
13{
18 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
20 public class DataPortalException : Exception
21 {
28 public DataPortalException(string message, object businessObject)
29 : base(message)
30 {
31 _innerStackTrace = String.Empty;
32 _businessObject = businessObject;
33 }
34
42 public DataPortalException(string message, Exception ex, object businessObject)
43 : base(message, ex)
44 {
45 _innerStackTrace = ex.StackTrace;
46 _businessObject = businessObject;
47 }
48
58 public DataPortalException(string message, Exception ex)
59 : base(message, ex)
60 {
61 _innerStackTrace = ex.StackTrace;
62 }
63
64#if !NETSTANDARD2_0 && !NET5_0
69 public DataPortalException(WcfPortal.WcfErrorInfo info)
70 : base(info.Message)
71 {
73 }
74#endif
75
81 : base(info.Message)
82 {
83 this.ErrorInfo = info;
84 }
85
90 public override string ToString()
91 {
92 var sb = new System.Text.StringBuilder();
93 sb.AppendLine(base.ToString());
94 if (ErrorInfo != null)
95 {
96 sb.AppendLine("------------------------------");
97 var error = this.ErrorInfo;
98 while (error != null)
99 {
100 sb.AppendFormat("{0}: {1}", error.ExceptionTypeName, error.Message);
101 sb.Append(Environment.NewLine);
102 sb.Append(error.StackTrace);
103 sb.Append(Environment.NewLine);
104 error = error.InnerError;
105 }
106 }
107 return sb.ToString();
108 }
109
117 public DataPortalErrorInfo ErrorInfo { get; private set; }
118
124 {
125 get
126 {
127 var result = ErrorInfo;
128 while (result.InnerError != null)
129 result = result.InnerError;
130 return result;
131 }
132 }
133
134 private object _businessObject;
135 private string _innerStackTrace;
136
149 public object BusinessObject
150 {
151 get { return _businessObject; }
152 }
153
154 private Exception _businessException;
155
165 public Exception BusinessException
166 {
167 get
168 {
169 if (_businessException == null)
170 {
171 _businessException = this.InnerException;
172 while (_businessException is Csla.Reflection.CallMethodException || _businessException is DataPortalException)
173 _businessException = _businessException.InnerException;
174 }
175 return _businessException;
176 }
177 }
178
186 {
187 get
188 {
189 if (ErrorInfo != null)
191 else if (BusinessException == null)
192 return Message;
193 else
194 return BusinessException.Message;
195 }
196 }
197
202 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.String.Format(System.String,System.Object,System.Object,System.Object)")]
203 public override string StackTrace
204 {
205 get { return String.Format("{0}{1}{2}", _innerStackTrace, Environment.NewLine, base.StackTrace); }
206 }
207
213 protected DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
214 : base(info, context)
215 {
216 _businessObject = info.GetValue("_businessObject", typeof(object));
217 _innerStackTrace = info.GetString("_innerStackTrace");
218 }
219
225 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
226#if !NET5_0
227 [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
228 [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)]
229#endif
230 public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
231 {
232 base.GetObjectData(info, context);
233 info.AddValue("_businessObject", _businessObject);
234 info.AddValue("_innerStackTrace", _innerStackTrace);
235 }
236 }
237}
This exception is returned for any errors occurring during the server-side DataPortal invocation.
override string ToString()
Gets a string representation of this object.
override string StackTrace
Get the combined stack trace from the server and client.
DataPortalException(DataPortalErrorInfo info)
Creates an instance of the object.
object BusinessObject
Returns a reference to the business object from the server-side DataPortal.
string BusinessExceptionMessage
Gets the Message property from the BusinessException, falling back to the Message value from the top-...
DataPortalErrorInfo BusinessErrorInfo
Gets the original exception error info that caused this exception.
override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
Serializes the object.
DataPortalErrorInfo ErrorInfo
Gets information about the original server-side exception.
DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
Creates an instance of the object for serialization.
DataPortalException(string message, Exception ex, object businessObject)
Creates an instance of the object.
DataPortalException(WcfPortal.WcfErrorInfo info)
Creates an instance of the object.
Exception BusinessException
Gets the original server-side exception.
DataPortalException(string message, Exception ex)
Creates an instance of the object.
DataPortalException(string message, object businessObject)
Creates an instance of the object.
override string ToString()
Returns a text representation of this object by returning the GetIdValue value in text form.
This exception is returned from the CallMethod method in the server-side DataPortal and contains the ...
Message containing details about any server-side exception.
string Message
Message from the exception object.
DataPortalErrorInfo InnerError
HttpErrorInfo object containing information about any inner exception of the original exception.
@ Serializable
Prevents updating or inserting until the transaction is complete.