attach FileWatcher eventhandlers dynamically
I'm trying to attach FileWatcher eventhandlers dynamically to a Windows Service. However the code cracks with the following message:
Exception:
{"Object does not match target type." }
Code:
f = a.GetType("System.IO.FileSystemWatcher", true, true);
fw = Activator.CreateInstance(f);
//set the eventhandler
ei = f.GetEvent("Changed");
ei.AddEventHandler(f, new
FileSystemEventHandler(FileListener.OnChanged));
ei = fw.GetType().GetEvent("Created");
ei.AddEventHandler(fw, new
FileSystemEventHandler(FileListener.OnChanged));
ei = fw.GetType().GetEvent("Deleted");
ei.AddEventHandler(fw, new
FileSystemEventHandler(FileListener.OnChanged));
ei = fw.GetType().GetEvent("Renamed");
ei.AddEventHandler(fw, new
RenamedEventHandler(FileListener.OnRenamed));
Any suggestions?
|