Reading app.config from a Windows Service

S

Sauron

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.config") 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("CABSServiceController.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.
 
E

eDubs

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top