views:

26

answers:

1

I'm iterating through all the types in GAC, GAC_32 and GAC_MSIL looking for specific types, fundamentally to match those using clauses in my source code, so when I compile the source. I'll know exactly what assembly dll's to provide.

I'm getting all the file names from each of those directory and applying GetTypes to each assembly in turn and comparing the returned types against my using list. But the problem I have is that GetTypes() keeps crapping out with an exception, when it can't load the types from a loaded assembly.

Is their any way to make GetTypes() less brittle. For instance, when parsing this assembly on my box, {blbmmc, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}, it craps out.

Any suggestions welcome.

I know this is a fairly lengthly process, but I figure i'll eventually use a subset of common assemblies to search, or possibly cache the list of types->assembly dll name at program start.

Thanks.

A: 

Continuing with my original comment, I would recommend to have a list of assemblies you actually need rather than searching for them.

Also, in the context of code generation, I don't know the scope of your task, but I found quite convenient using the CodeDOM for my projects when I needed classes generated from specific XML Schema.

But for tasks like 'create a method on the fly' Expression Trees are just awesome. (Especially in .NET 4.0)

Regent
Hi Regent, the code generation is pretty much set currently using a static list of assemblies supplied when the code is generated, but it would have been nice, even for security purposes to supply an exact list.
scope_creep