A
Alex
I am creating an application that allows the user to link a plug-in
"utility" class (Watcher) to a class at runtime. There are several
Watcher utilities, each with a different style of "watching"
something. The all inherit from BaseWatcher which implements an
IWatcher interface. To configure the Watcher we have a configuration
object per Watcher called <watcher_name>WatcherConfig inheriting from
BaseWatcherConfig which implements IWatcherConfig.
Each custom Watcher is implemented in a separate Assembly dll under
the xxxxx.xxxxx.Watcher namespace.
BaseWatcherConfig and all the Interfaces are available to the main
application.
Because the main application does not know which Watcher will be used
the references are stored as IWatcher and IWatcherConfig.
I want to reconstitute the serialised <watcher_name>WatcherConfig
object file as a BaseWatcherConfig and then use it to generate a
Watcher via the WatcherFactory, which accepts IWatcherConfig as a
building block
The <watcher_name>WatcherConfig is unknown to the main application
until after the dll is loaded with Assembly.LoadFile().
So I have a SOAP formatted <watcher_name>WatcherConfig object map
serialised to disk which I want to reconstitute and as a
BaseWatcherConfig. I am using:
IWatcher _watcher = (IWatcher)watcherFactory.GetWatcher((IWatcherConfig)BaseWatcherConfig.Deserialize(_watcherConfigFile.FullName));
The deserialize routine:
...
SoapFormatter formatter = new SoapFormatter();
BaseWatcherConfig liveObject =
(BaseWatcherConfig)formatter.Deserialize(fileStream);
...
The exception thrown when executing the Deserialze line is:
"Parse Error, no assembly associated with Xml key
a1:http://schemas.microsoft.com/clr/ns...6.38412, Culture=neutral, PublicKeyToken=null
FolderWatcherConfig"
So..I take it I can't do this, so the question is... If I load all
available Watcher assemblies from disk at application load that will
then allow me to cast the serialised object corectly:
<watcher_name>WatcherConfig liveObject =
(<watcher_name>WatcherConfig)formatter.Deserialize(fileStream);
So how, short of a HUGE switch statement (which defeats the point),
can I make this cast selection dynamic.. I have the name of the custom
Watcher so I can generate a string with the Type name like:
watcherName+"Config"
How has I get this into the cast with any elegance ?
Any help much appreciated,
Al
"utility" class (Watcher) to a class at runtime. There are several
Watcher utilities, each with a different style of "watching"
something. The all inherit from BaseWatcher which implements an
IWatcher interface. To configure the Watcher we have a configuration
object per Watcher called <watcher_name>WatcherConfig inheriting from
BaseWatcherConfig which implements IWatcherConfig.
Each custom Watcher is implemented in a separate Assembly dll under
the xxxxx.xxxxx.Watcher namespace.
BaseWatcherConfig and all the Interfaces are available to the main
application.
Because the main application does not know which Watcher will be used
the references are stored as IWatcher and IWatcherConfig.
I want to reconstitute the serialised <watcher_name>WatcherConfig
object file as a BaseWatcherConfig and then use it to generate a
Watcher via the WatcherFactory, which accepts IWatcherConfig as a
building block
The <watcher_name>WatcherConfig is unknown to the main application
until after the dll is loaded with Assembly.LoadFile().
So I have a SOAP formatted <watcher_name>WatcherConfig object map
serialised to disk which I want to reconstitute and as a
BaseWatcherConfig. I am using:
IWatcher _watcher = (IWatcher)watcherFactory.GetWatcher((IWatcherConfig)BaseWatcherConfig.Deserialize(_watcherConfigFile.FullName));
The deserialize routine:
...
SoapFormatter formatter = new SoapFormatter();
BaseWatcherConfig liveObject =
(BaseWatcherConfig)formatter.Deserialize(fileStream);
...
The exception thrown when executing the Deserialze line is:
"Parse Error, no assembly associated with Xml key
a1:http://schemas.microsoft.com/clr/ns...6.38412, Culture=neutral, PublicKeyToken=null
FolderWatcherConfig"
So..I take it I can't do this, so the question is... If I load all
available Watcher assemblies from disk at application load that will
then allow me to cast the serialised object corectly:
<watcher_name>WatcherConfig liveObject =
(<watcher_name>WatcherConfig)formatter.Deserialize(fileStream);
So how, short of a HUGE switch statement (which defeats the point),
can I make this cast selection dynamic.. I have the name of the custom
Watcher so I can generate a string with the Type name like:
watcherName+"Config"
How has I get this into the cast with any elegance ?
Any help much appreciated,
Al