Subject: attach FileWatcher eventhandlers dynamically
Posted By: neethling Post Date: 1/11/2006 9:17:33 AM
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?

Go to topic 38587

Return to index page 398
Return to index page 397
Return to index page 396
Return to index page 395
Return to index page 394
Return to index page 393
Return to index page 392
Return to index page 391
Return to index page 390
Return to index page 389