Brian,
Why do you have an assembly.dll.config? You should take your config
settings and place them in the config file for the application that is using
the assemblies. This is the recommended way of doing it, and the way the
config classes have been set up.
But in regards to your question, if you want code to run in an assembly
when loaded, you will have to execute the code manually.
My recommendation is to create an attribute which takes a type. The
assemblies would then apply the attribute on the assembly level, and you
would get the attribute in your calling code through reflection. Then, you
can get the type.
Now, you can either call a static method with a known signature on the
type, or (and I would do this), create an interface that the type will
implement, and then create an instance of that type.
Then, you execute the methods on the interface implementation, and you
are done.
You might want to keep a flag indicating that the code was run as well.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Brian Richards" <br*******@gmail.com> wrote in message
news:eY**************@TK2MSFTNGP04.phx.gbl...
Is it possible to run code in an assembly when it's loaded? In my case I
have an assembly that requires that the users path be setup correctly or
GetTypes() will throw an exception. Looking for a work around to just
requiring the user to have the Path environment setup in the calling
application.
class MyAssemblyLoader
{
public Type[] GetTypes(String assemblyName)
{
Assembly assembly = Assembly.Load(assemblyName); //causes code in
assemblyName to run and set Environment path from Assembly.dll.config
return assembly.GetTypes();
}
}