@@ -43,17 +43,21 @@ private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog
43
43
if ( ! isInner )
44
44
error . Modules = GetLoadedModules ( log ) ;
45
45
46
- error . PopulateStackTrace ( error , exception ) ;
46
+ error . PopulateStackTrace ( error , exception , log ) ;
47
47
48
48
try {
49
49
PropertyInfo info = type . GetProperty ( "HResult" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
50
50
if ( info != null )
51
51
error . Code = info . GetValue ( exception , null ) . ToString ( ) ;
52
52
} catch ( Exception ) { }
53
53
54
- if ( exception . TargetSite != null ) {
55
- error . TargetMethod = new Method ( ) ;
56
- error . TargetMethod . PopulateMethod ( error , exception . TargetSite ) ;
54
+ try {
55
+ if ( exception . TargetSite != null ) {
56
+ error . TargetMethod = new Method ( ) ;
57
+ error . TargetMethod . PopulateMethod ( error , exception . TargetSite ) ;
58
+ }
59
+ } catch ( Exception ex ) {
60
+ log . Error ( typeof ( ExceptionlessClient ) , ex , "Error populating TargetMethod: " + ex . Message ) ;
57
61
}
58
62
59
63
try {
@@ -110,45 +114,49 @@ private static string GetMessage(this Exception exception) {
110
114
private static ModuleCollection GetLoadedModules ( IExceptionlessLog log , bool includeSystem = false , bool includeDynamic = false ) {
111
115
var modules = new ModuleCollection ( ) ;
112
116
113
- int id = 1 ;
114
- foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) ) {
115
- if ( ! includeDynamic && assembly . IsDynamic )
116
- continue ;
117
-
118
- try {
119
- if ( ! includeDynamic && String . IsNullOrEmpty ( assembly . Location ) )
117
+ try {
118
+ int id = 1 ;
119
+ foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) ) {
120
+ if ( ! includeDynamic && assembly . IsDynamic )
120
121
continue ;
121
- } catch ( SecurityException ex ) {
122
- const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust." ;
123
- log . Error ( typeof ( ExceptionlessClient ) , ex , message ) ;
124
- }
125
122
126
- if ( ! includeSystem ) {
127
123
try {
128
- string publicKeyToken = assembly . GetAssemblyName ( ) . GetPublicKeyToken ( ) . ToHex ( ) ;
129
- if ( _msPublicKeyTokens . Contains ( publicKeyToken ) )
130
- continue ;
131
-
132
- object [ ] attrs = assembly . GetCustomAttributes ( typeof ( GeneratedCodeAttribute ) , true ) ;
133
- if ( attrs . Length > 0 )
124
+ if ( ! includeDynamic && String . IsNullOrEmpty ( assembly . Location ) )
134
125
continue ;
135
- } catch { }
136
- }
137
-
138
- var module = assembly . ToModuleInfo ( ) ;
139
- if ( module . ModuleId > 0 )
140
- continue ;
126
+ } catch ( SecurityException ex ) {
127
+ const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust." ;
128
+ log . Error ( typeof ( ExceptionlessClient ) , ex , message ) ;
129
+ }
130
+
131
+ if ( ! includeSystem ) {
132
+ try {
133
+ string publicKeyToken = assembly . GetAssemblyName ( ) . GetPublicKeyToken ( ) . ToHex ( ) ;
134
+ if ( _msPublicKeyTokens . Contains ( publicKeyToken ) )
135
+ continue ;
136
+
137
+ object [ ] attrs = assembly . GetCustomAttributes ( typeof ( GeneratedCodeAttribute ) , true ) ;
138
+ if ( attrs . Length > 0 )
139
+ continue ;
140
+ } catch { }
141
+ }
142
+
143
+ var module = assembly . ToModuleInfo ( ) ;
144
+ if ( module . ModuleId > 0 )
145
+ continue ;
141
146
142
- module . ModuleId = id ;
143
- modules . Add ( module ) ;
147
+ module . ModuleId = id ;
148
+ modules . Add ( module ) ;
144
149
145
- id ++ ;
150
+ id ++ ;
151
+ }
152
+ } catch ( Exception ex ) {
153
+ log . Error ( typeof ( ExceptionlessClient ) , ex , "Error loading modules: " + ex . Message ) ;
146
154
}
147
155
148
156
return modules ;
149
157
}
150
158
151
- private static void PopulateStackTrace ( this Error error , Error root , Exception exception ) {
159
+ private static void PopulateStackTrace ( this Error error , Error root , Exception exception , IExceptionlessLog log ) {
152
160
StackFrame [ ] frames = null ;
153
161
try {
154
162
var st = new StackTrace ( exception , true ) ;
@@ -159,7 +167,7 @@ private static void PopulateStackTrace(this Error error, Error root, Exception e
159
167
return ;
160
168
161
169
foreach ( StackFrame frame in frames ) {
162
- var stackFrame = new Exceptionless . Models . Data . StackFrame {
170
+ var stackFrame = new Models . Data . StackFrame {
163
171
LineNumber = frame . GetFileLineNumber ( ) ,
164
172
Column = frame . GetFileColumnNumber ( ) ,
165
173
FileName = frame . GetFileName ( )
@@ -168,7 +176,11 @@ private static void PopulateStackTrace(this Error error, Error root, Exception e
168
176
stackFrame . Data [ "ILOffset" ] = frame . GetILOffset ( ) ;
169
177
stackFrame . Data [ "NativeOffset" ] = frame . GetNativeOffset ( ) ;
170
178
171
- stackFrame . PopulateMethod ( root , frame . GetMethod ( ) ) ;
179
+ try {
180
+ stackFrame . PopulateMethod ( root , frame . GetMethod ( ) ) ;
181
+ } catch ( Exception ex ) {
182
+ log . Error ( typeof ( ExceptionlessClient ) , ex , "Error populating StackFrame method info: " + ex . Message ) ;
183
+ }
172
184
173
185
error . StackTrace . Add ( stackFrame ) ;
174
186
}
@@ -181,7 +193,7 @@ private static void PopulateMethod(this Method method, Error root, MethodBase me
181
193
method . Name = methodBase . Name ;
182
194
if ( methodBase . DeclaringType != null ) {
183
195
method . DeclaringNamespace = methodBase . DeclaringType . Namespace ;
184
- if ( methodBase . DeclaringType . MemberType == MemberTypes . NestedType )
196
+ if ( methodBase . DeclaringType . MemberType == MemberTypes . NestedType && methodBase . DeclaringType . DeclaringType != null )
185
197
method . DeclaringType = methodBase . DeclaringType . DeclaringType . Name + "+" + methodBase . DeclaringType . Name ;
186
198
else
187
199
method . DeclaringType = methodBase . DeclaringType . Name ;
0 commit comments