473,467 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Build Errors on C# Console App

I'm trying to compile the FileSystemWatcher example on MSDN but it won't
compile and gives the following build error:

1) An object reference is required for the nonstatic field, method, or
property 'FileWatcherDaemon.fileWatcher.OnChanged(object,
System.IO.FileSystemEventArgs)'

This is given on the following line:

watcher.Changed += new FileSystemEventHandler(Changed);
Nov 15 '05 #1
2 3558
dm_dal <dm******@yahoo.com> wrote:
I'm trying to compile the FileSystemWatcher example on MSDN but it won't
compile and gives the following build error:

1) An object reference is required for the nonstatic field, method, or
property 'FileWatcherDaemon.fileWatcher.OnChanged(object,
System.IO.FileSystemEventArgs)'

This is given on the following line:

watcher.Changed += new FileSystemEventHandler(Changed);


The above line doesn't exist in the sample - it's OnChanged, not
Changed.

I've just cut and paste the original from MSDN, and it compiles fine.
Which version of the MSDN are you using?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
Must have been a typo in my first post.
Here's all the code. But I still get the same error.
using System;
using System.IO;

namespace FileWatcherDaemon
{
/// <summary>
/// Summary description for fileWatcher.
/// </summary>
public class fileWatcher
{

public static void Main()
{
string[] args = System.Environment.GetCommandLineArgs();
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "C:\\Temp";
watcher.Filter = "*.txt";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.EnableRaisingEvents = true;
watcher.Changed += new FileSystemEventHandler(OnChanged);
Console.WriteLine("Press \'q\' to Quit");
while(Console.Read()!='q');
}

private void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine("File Changed");
Console.WriteLine("file: " + e.Name.ToString());
}
}
}
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP***********************@news.microsoft.com. ..
dm_dal <dm******@yahoo.com> wrote:
I'm trying to compile the FileSystemWatcher example on MSDN but it won't
compile and gives the following build error:

1) An object reference is required for the nonstatic field, method, or property 'FileWatcherDaemon.fileWatcher.OnChanged(object,
System.IO.FileSystemEventArgs)'

This is given on the following line:

watcher.Changed += new FileSystemEventHandler(Changed);


The above line doesn't exist in the sample - it's OnChanged, not
Changed.

I've just cut and paste the original from MSDN, and it compiles fine.
Which version of the MSDN are you using?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
1
by: David Alloza | last post by:
Hello, I have exactly the same problem as this guy, but in the case of a ( final ) commercial version of .NET2005. ...
1
by: | last post by:
I'm having a problem finding the cause for this problem. I have a solution in Visual Studio 2005 that contains two projects -- a Web Site and a Class Library. The web site references the class...
5
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get my browser to report javascript errors?...
0
by: anupamak | last post by:
hello, I created a win32 project(precompiled headers, console application). This was created to create a service( for which i used SERVICE_TABLE_ENTRY, SERVICE_STATUS, SERVICE_STATUS_HANDLE,...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get my browser to report javascript errors?...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.