Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 14th, 2011, 12:42 PM
Authorized User
Points: 149, Level: 2
Points: 149, Level: 2 Points: 149, Level: 2 Points: 149, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Location: Belgrade,Serbia
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
Default Chapter 21 Try it out,page 718

OnRenamed Metod throws an error:

public void OnRenamed(object source, RenamedEventArgs e)
{
try
{
StreamWriter sw = new StreamWriter(@"C:\FileLogs\Log.txt", true);
sw.WriteLine("File: {0} {1}", e.OldName, e.FullPath);
sw.Close();
this.BeginInvoke(new updatewatchertextdelegate(UPDATEWATCHTEXT), "wrote renamed event to log");
}

catch (IOException)
{
this.BeginInvoke(new updatewatchertextdelegate(UPDATEWATCHTEXT), "error writing to log");
}

}





Error 1 No overload for 'OnRenamed' matches delegate 'System.IO.FileSystemEventHandler' C:\source\Chapter21\filewatch\filewatch\Form1.cs 91 37 filewatch
  #2 (permalink)  
Old December 14th, 2011, 04:55 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

To give you information on how to find this error - what does this error give on information?
Error 1 No overload for 'OnRenamed' matches delegate 'System.IO.FileSystemEventHandler'
This means that the parameters and return types of the OnRenamed method do not match the parameters and return types defined by the FileSystemEventHandler.

The method OnRenamed is defined with a void return type and object, RenamedEventArgs parameters. The FileSystemEventHandler delegate is defined this way:
Code:
public delegate void FileSystemEventHandler(object sender, FileSystemEventArgs e);
So the second parameter of OnRenamed could be changed to FileSystemEventArgs instead of RenamedEventArgs.

However, checking further where the method OnRenamed is applied to, it should be with the Renamed event of the FileSystemWatcher. This event is of type RenamedEventHandler. The RenamedEventHandler delegate matches the parameters you've defined with the OnRenamed method. So you probably assigned the OnRenamed method to a different event that is of type FileSystemEventHandler, e.g. Deleted, Changed, or Created.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
dampyr (December 15th, 2011)
  #3 (permalink)  
Old December 15th, 2011, 06:21 AM
Authorized User
Points: 149, Level: 2
Points: 149, Level: 2 Points: 149, Level: 2 Points: 149, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Location: Belgrade,Serbia
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
Default

I have found error:

this.watcher.Renamed += new RenamedEventHandler(this.onrenamed);


instead of " RenamedEventHandler",i wrote "FileSystemEventHandler"


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 21 Try it out,page 693 dampyr BOOK: Beginning Visual C# 2010 0 December 11th, 2011 09:44 AM
list_entry(), page 21 logicman112 BOOK: Professional Linux Kernel Architecture ISBN: 978-0-470-34343-2 1 March 19th, 2009 03:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.