0

I'm writing a program that uses reflection to look at a DLL, and obtain the table names/enums within.

After obtaining the assembly using the method "ReflectionOnlyLoadFrom" to avoid having to load all dependencies, I use the following code to grab the types:

try
{
    types = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
    types = ex.Types.Where(p => p != null).ToArray();
}

This returns most of the types, but the ones I really need are not listed here.

The commonality between the missing types are that they all use Custom Attributes in the class (C#) as part of the data access layer. The table is defined above the class name in an attribute, and each property has an attribute above it to define it as a column in the DB.

Could custom attributes be causing an issue in relation to reflection, in that types aren't returned when they are present?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
fypfyp
  • 206
  • 4
  • 10
  • 2
    Is it hitting your catch block? It would not surprise me if this failed on a custom attribute if that attribute is defined elsewhere. See: http://stackoverflow.com/questions/2321293/assembly-reflectiononlyloadfrom-not-working – stephen.vakil Apr 14 '16 at 14:02
  • Yep, I forgot to mention "GetTypes()" never gets hit, it always goes in to the catch and gets the types from the ReflectionTypeLoadException. – fypfyp Apr 14 '16 at 14:20
  • I was previously using "AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve" but using the code given in the answer to that SO link has done the trick. Thanks! – fypfyp Apr 14 '16 at 14:31

0 Answers0