Hi,
I have an internal class, which an internal constructor. In the same
assembly as this class, I have a factory class which uses
Activator.CreateInstance to create the instance. The code is as
follows:
ISubscriptionChangeWatcher result;
string[] watcherConfig;
ObjectHandle handle;
if
( ConfigurationManager.AppSettings[ "SubscriptionWatcher" ] == null )
{
throw new InvalidOperationException(
Properties.Resources.WatcherNotConfigured
);
}
// This is like this string:
MedAssociates.Test.SubscriptionManager.TestProcess or,MedSubscriptionManager.Business.Test
watcherConfig = ConfigurationManager.AppSettings[
"SubscriptionWatcher" ].Split( ',' );
if ( watcherConfig.Length != 2 ) {
throw new InvalidOperationException(
Properties.Resources.WatcherNotConfigured
);
}
handle = Activator.CreateInstance(
watcherConfig[ 1 ],
watcherConfig[ 0 ]
);
result = (ISubscriptionChangeWatcher)handle.Unwrap();
return result;
For some reason, everything works fine via NUnit tests, which are in a
seperate assembly. InternalsVisiableTo allows the testing assembly to
see internals of the assembly with the above code.
In my application, I get a MissingMethodException. I was under the
impression that Activator could call constructor code on any member
even if its not directly visible to it. Is this not the case? how is
this usually acomplished.. I know this method of specifing a type to
load via a config file is common.
Thanks
Andy