Im using reflection to check attributes of the methods.
Going deeper and deeper using reflection and checking classes inheritance.
I need to stop when class is .NET Framework, not my own.
How i can check this ?
Thx
I guess you should move to:
exception.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
and investigate retrieved attribute for value
If you want to check an assembly is published by Microsoft, you could do something like this:
public static bool IsMicrosoftType(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
if (type.Assembly == null)
return false;
object[] atts = type.Assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if ((atts == null) || (atts.Length == 0))
return false;
AssemblyCompanyAttribute aca = (AssemblyCompanyAttribute)atts[0];
return aca.Company != null && aca.Company.IndexOf("Microsoft Corporation", StringComparison.OrdinalIgnoreCase) >= 0;
}
It's not bullet proof as anyone could add such an AssemblyCompany attribute to a custom assembly, but it's a start. For more secure determination, you would need to check Microsoft's authenticode signature from the assembly, like what's done here: Get timestamp from Authenticode Signed files in .NET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With