Hello Larry!
What do you meen by "the IDE" in this context? The IDE doen't matter here.
... but obviously the assembly is loaded in my own app (and
already bound to the main thread)
An Assembly is never bound to a Thread, only to an AppDomain.
Are you absolutly sure that it isn't something in you code that causes the
error? If you are not able to reproduce this, it will be hard (likely
impossible) for anybody (including MS Support Team) to find out what may be
wrong.
and have to proceed as if the assembly is not
loaded.
You can easly get any Type-Instance of a Type in a (as far) not loaded
Assembly by specifing the Assembly-Qualified Name.
If the Assembly has not been loaded, it will be loaded by this operation,
and the class (and depend classes) will be initialized.
Of cause the Assembly must be reachable in any way (eigther through GAC
installation or through being within the search-path). It doesn't matter if
the assembly is reference or not. It must be just there.
That being the case, do you know what the general steps are
for doing this. Since I'm just reading ".cs" files in a project,
You source .cs files??? This sounds like a compilation time "feature".
looking for the "Type" of classes defined in these files (their base
classes that is), I'm assuming that for each base class I'm
interested in, I can just iterate all referenced assemblies in the
project looking for the class' type (e.g.,
"System.Windows.Forms.Form" for instance). By "referenced
assemblies", I mean those assemblies listed under the "References"
folder seen under all projects in Solution Explorer
Forget about this IDE things. At runtime there is no IDE.
An example:
You can set a reference to anything you like within your IDE. The referenced
Assemblies will only be included as references within the Assemblies
Manifest if they are _actually used_ by your code.
You can get a List of referenced Assemblies by calling the Assemblies
"GetReferencedAssemblies()" method. But it will only return "AssemblyName"
objects. If you need the "Assembly" Instance you have to go through
AppDomain.GetAssemblies() or through Assembly.Load().
(since all base
classes in all ".cs" files must be referenced there presumably - is
this correct?).
Yes.
I already know how to get the list of assemblies seen under the
"References" folder of each project but which functions do I then
call in order to look up a string in the form
"<NameSpace>.<ClassName>" (in order to return its assembly-qualified
name).
From the CLR's point of view the Namespace is just on part of the Assembly's
name (there is no "Namespace" property of the Assembly). What would be
possible (but I won't recomment this) is to get all Types of an Assembly by
it's .GetTypes() method and to lookup the Namespace.ClassName Type within
that list.
Do not use this that way. Just use Assembly Qualified Names and all will
work "automaticly". Do do not have to care about when an Assembly will be
loaded or something like that.
Type t = Type.GetType("System.Windows.Forms.Form, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
If you do not what to specify this "long and complex" Assembly Qualified
Name (it is realy not very user-friendly ;-)), setup a kind of default
(fallback) logic. If you are dealing with Types from strings there will be a
configuration file (or other form of persistent storage) which holds this
strings.
You can implement a simple "Namespace->Assembly Parameters" mapping:
e.g.
<anyTag>
<assemblyMappings>
<assemblyMapping
namespace="System.Windows.Forms"
version="2.0"
culture="neutral"
publicKeyToken="b77a5...." />
<assemblyMapping
namespace="...."
...
/>
</assemblyMappings>
</anyTag>
* If a full assembly qualified name is entered, you don't have to do
anything
* If the name is only "Namespace.Class", you have to lookup within the
"assemblyMappings" to get the other parameters
* If no corresponding "assemblyMapping" is found, throw an Exception
(configuration error).
Now you have the Assembly Qualified Name, which can be passed to
Type.GetType(...).
By using the Architecture, you can avoid all unnessersary Reflection stuff,
looping through Assemblies, References and Types.
GP