Skip to content

Commit

Permalink
fixes #264
Browse files Browse the repository at this point in the history
  • Loading branch information
petrsvihlik committed Feb 5, 2021
1 parent 33a4422 commit c136595
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ internal static string GetSdk()
internal static string GetSource()
{
Assembly originatingAssembly = GetOriginatingAssembly();

var attribute = originatingAssembly.GetCustomAttributes<DeliverySourceTrackingHeaderAttribute>().FirstOrDefault();
if (attribute != null)
if (originatingAssembly != null)
{
return GenerateSourceTrackingHeaderValue(originatingAssembly, attribute);
var attribute = originatingAssembly.GetCustomAttributes<DeliverySourceTrackingHeaderAttribute>().FirstOrDefault();
if (attribute != null)
{
return GenerateSourceTrackingHeaderValue(originatingAssembly, attribute);
}
}
return null;
}
Expand Down Expand Up @@ -127,10 +129,11 @@ internal static string GenerateSourceTrackingHeaderValue(Assembly originatingAss
internal static Assembly GetOriginatingAssembly()
{
var executingAssembly = Assembly.GetExecutingAssembly();
// Get the whole stack trace, get involved assemblies, and determine which one references this SDK
var callerAssemblies = new StackTrace().GetFrames()
.Select(x => x.GetMethod().ReflectedType?.Assembly).Distinct().OfType<Assembly>()
.Where(x => x.GetReferencedAssemblies().Any(y => y.FullName == executingAssembly.FullName));
var originatingAssembly = callerAssemblies.Last();
var originatingAssembly = callerAssemblies.Any() ? callerAssemblies.Last() : null;
return originatingAssembly;
}
}
Expand Down

0 comments on commit c136595

Please sign in to comment.