Skip to content

Commit 54dc15b

Browse files
niemyjskiejsmith
authored andcommitted
Fixed a bug with reading client configuration attributes on .net standard
1 parent 64cb565 commit 54dc15b

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -154,11 +154,13 @@ public static void ReadFromAttributes(this ExceptionlessConfiguration config, IC
154154
throw new ArgumentNullException("config");
155155

156156
if (assemblies == null) {
157-
assemblies = new List<Assembly> {
158-
#if NET45
159-
Assembly.GetCallingAssembly()
157+
Assembly callingAssembly = null;
158+
#if NET45 || NETSTANDARD2_0
159+
try {
160+
callingAssembly = Assembly.GetCallingAssembly();
161+
} catch (PlatformNotSupportedException) { }
160162
#endif
161-
};
163+
assemblies = new List<Assembly> { callingAssembly };
162164
}
163165

164166
assemblies = assemblies.Where(a => a != null).Distinct().ToList();
@@ -182,7 +184,7 @@ public static void ReadFromAttributes(this ExceptionlessConfiguration config, IC
182184

183185
foreach (var assembly in assemblies) {
184186
var attributes = assembly.GetCustomAttributes(typeof(ExceptionlessSettingAttribute));
185-
foreach (ExceptionlessSettingAttribute attribute in attributes.OfType<ExceptionlessSettingAttribute>()) {
187+
foreach (var attribute in attributes.OfType<ExceptionlessSettingAttribute>()) {
186188
if (!String.IsNullOrEmpty(attribute.Name))
187189
config.Settings[attribute.Name] = attribute.Value;
188190
}
@@ -258,13 +260,10 @@ public static void ReadAllConfig(this ExceptionlessConfiguration config, params
258260
#if NETSTANDARD1_5
259261
config.ReadFromAttributes(Assembly.GetEntryAssembly());
260262
#elif NET45 || NETSTANDARD2_0
261-
Assembly callingAssembly;
263+
Assembly callingAssembly = null;
262264
try {
263265
callingAssembly = Assembly.GetCallingAssembly();
264-
}
265-
catch (PlatformNotSupportedException) {
266-
callingAssembly = null;
267-
}
266+
} catch (PlatformNotSupportedException) { }
268267

269268
config.ReadFromAttributes(Assembly.GetEntryAssembly(), callingAssembly);
270269
#endif

src/Exceptionless/Utility/AssemblyHelper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
namespace Exceptionless.Utility {
99
public class AssemblyHelper {
1010
public static Assembly GetRootAssembly() {
11-
#if NETSTANDARD1_5
11+
#if NET45 || NETSTANDARD2_0 ||NETSTANDARD1_5
1212
return Assembly.GetEntryAssembly();
13-
#elif NET45 || NETSTANDARD2_0
14-
return Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly();
1513
#else
1614
return null;
1715
#endif
1816
}
1917

2018
public static string GetAssemblyTitle() {
2119
// Get all attributes on this assembly
22-
Assembly assembly = GetRootAssembly();
20+
var assembly = GetRootAssembly();
2321
if (assembly == null)
2422
return String.Empty;
2523

0 commit comments

Comments
 (0)