Type Resolution Sample
This sample demonstrates how user
written code can participate in NGWS's type resolution
process. NGWS has a well defined set of rules it uses to
locate the assembly containing a given referenced type.
However, if the target
assembly cannot be found through normal means, an event is raised that
callers can use to specify which assembly the requested type is
in. This feature will not typically be used in most
programs. It is intended for advanced scenarios where callers have
custom loading semantics that can't be satisfied using the default rules
established by NGWS.
In this sample we are going to highlight the following topics:
- Loading Assemblies
- Dynamically invoking members on types
- Writing event handlers used to resolve type references
- Using Reflection Emit to create an transient
assembly
Sample Tour
This
sample consists of a main program called host.exe that dynamically loads an
assembly called first.dll and executes a method on a type in that
assembly. The method that is executed makes reference to a type in an
assembly that doesn't exist. When first.dll is loaded, host.exe
registers an event handler that will be used to provide NGWS with the assembly
containing the referenced type.
When the event
handler is called, host.exe uses Reflection Emit to create an assembly on the
fly. This assembly contains the type that has been referenced from the
first assembly.
Sample Location
- This sample is located in the
typeresolve
directory under the NGWS SDK samples directory.
For Example:
C:\Program Files\NGWSSDK\Samples\typeresolve
Build Instructions
-
This sample is built by typing nmake all
in the typeresolve
directory.
For Example:
C:\Program
Files\NGWSSDK\Samples\typeresolve>NMAKE ALL
How to Run
- Run host.exe
from the command line. The following output should be
displayed:
Event Handler Called
Method called in second assembly
Done.