473,378 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reading app.config from a Windows Service

Hi all

I have created a Service that will listen for incoming requests from client
computers and communicate with my .NET remoting objects to send data back.

My problem is when I start the Service. I call the
RemotingConfiguration.Configure("appname.exe.confi g") method, but I get a
System.IO.FileNotFoundException at that line. The file does exist in the
same directory as the Service's executable.

Is there something different I need to know about when using Windows
Services and app.config files? I have the same method working fine in a
regular executable, but I want to implement the Service.

I attached to the process when the service was running to step through the
code. I also tried trapping for the exception to write it to the event log,
when I step through the exception is thrown and the line that contains the
EventLog.WriteEntry is executed, but nothing appears in the event log. Also,
I have a general Catch block after the File catch block that also gets
executed, and this DOES appear in the EventLog. I though that only 1 Catch
block was executed when an error has ocurred?!?!

Here is my code, at the moment in the OnResume method as you cannot debug
the OnStart method:
--------------------------------------------------
Try
RemotingConfiguration.Configure("CABSServiceContro ller.exe.config")
EventLog.WriteEntry("CABS Service is now listening for incoming
requests", EventLogEntryType.Information)

Catch FileEx As System.IO.FileNotFoundException
EventLog.WriteEntry("The specified file '" & FileEx.FileName & "'
cannot be found" _
& vbCrLf & "Stack Trace: " &
FileEx.StackTrace, EventLogEntryType.Error)
'// This gets executed but not logged
Catch Ex As Exception
EventLog.WriteEntry("A general error has occurred." _
& vbCrLf & "Source: " & Ex.Source _
& vbCrLf & "Message: " & Ex.Message _
& vbCrLf & "Stack Trace: " &
Ex.StackTrace, EventLogEntryType.Error)
'// This also gets executed but DOES get logged
End Try
----------------------------------------------------

If anyone has any insight into this I would be very grateful.

Kind Regards,
Steve.
Jul 21 '05 #1
1 2341

Steve, when your app is running as a windows service, it's actually
running in the System32 folder, and not in the directory where it was
installed (ie: c:\program files\AppName\).

That's why you're getting a File Not Found error.

Hope that helps.

- Eric
eDubs
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message314493.html

Jul 21 '05 #2

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

Similar topics

16
by: DraguVaso | last post by:
Hi, I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application...
2
by: bmcelhany | last post by:
Hi all, I have a solution with 4 projects: a class library, a windows app, a windows service, and an installer project. The class library handles all communication with the database and its...
5
by: Dhilip Kumar | last post by:
Hi All, I'm writing a Windows Service app using C#. I need to read some configuration settings before the service starts up. These settings will be used by the service in its operation. ...
2
by: Dan | last post by:
Hi there, I've got a WebService application that works fine under Windows 2000 with Framework 1.0 Installing it on Windows 2003 results in SoapExceptions being thrown when any of the methods...
1
by: Sauron | last post by:
Hi all I have created a Service that will listen for incoming requests from client computers and communicate with my .NET remoting objects to send data back. My problem is when I start the...
0
by: Salty Dog | last post by:
I have the config file named properly but maybe I don't have it in the proper location. I have it in the root of the project folder. Is there someplace that I need to configure the Windows...
4
by: PeterW | last post by:
I have a Windows service that needs to get some values from a config file. I place the config file for the service in the System32 directory. I do not get the values using the usual...
14
by: Peter | last post by:
..NET 3.5 I have a Windows Service application and it does remoting, but when a client incounters an error the client get the following error message "Server encountered an internal error....
2
by: Steven Cheng | last post by:
Hi Gary, As for the setting you mentioned, it is used to custimze the received data size limitation of WCF binding(such as NetTcpBinding or HttpBinding). After you have definite a customized...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.