Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4071824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:48:22+00:00 2026-05-20T16:48:22+00:00

I have developed a service with vb.net. This service is been installed from a

  • 0

I have developed a service with vb.net.

This service is been installed from a windows application which close immediately after the Service starts.
Inside the service I have a procedure “Protected Overrides Sub OnCustomCommand
“, this procedure works fine until the pointer comes to instruction which I give you below:

    Protected Overrides Sub OnCustomCommand(ByVal command As Integer)
                StartLogFile("Custom Command {" & command & "} invoked", EventLogEntryType.Information)
                Dim Position As String
                Dim myFile As String = Nothing
                Dim myTime As String = Nothing
                Try
                    If command = SimpleServiceCustomCommands.StartWorker Then
                        Position = "GetKeyValue Time"
                        myTime = GetKeyValue("Time", "", RegPath)
                        Position = "GetKeyValue Name"
                        myFile = GetKeyValue("Name", "", RegPath)
                        StartLogFile("Notice OnCustomCommand" & vbNewLine & "MyTime= { " & myTime & "}, {MyFile= { " & myFile & "} ", EventLogEntryType.Error)
    .
    .
    .
    Catch ex As Exception
                    StartLogFile("Error OnCustomCommand" & vbNewLine & Position & vbNewLine & ex.StackTrace, EventLogEntryType.Error)
                Finally
                End Try

I made some changes according to notices i read and now the GetKeyValue did not returns me any error. But either did not returns me any value.

The function Get is as follows:

Public Function GetKeyValue(ByVal nKey As String, ByVal vKey As String, ByVal sPath As String) As String
        Dim RegKey As RegistryKey
        Dim kValue As String = Nothing
        Dim Pos As String
        If RegKeyExists(sPath) Then
            Try
                RegKey = Registry.CurrentUser.OpenSubKey(sPath, True)
                kValue = CStr(RegKey.GetValue(nKey))
            Catch ex As Exception
                StartLogFile(" GetKeyValue, RegKeyExists(sPath) " & vbNewLine & "{ RegKey= " & RegKey.Name & "}, { kValue= " & kValue & "}, { nKey= " & nKey & "}" & vbNewLine & "Stack Trace= " & ex.StackTrace, EventLogEntryType.Warning)
            End Try
        End If
        Return kValue
    End Function

Now what I have is:
No Error, No Values
!!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:48:23+00:00Added an answer on May 20, 2026 at 4:48 pm

    Your code obviously didn’t fail inside the try-catch statement inside GetKeyValue() because then you’ll see from the log that the error came from inside that function itself.

    So your code must be either be failing on the “False” case, or form the StartLogFile() call in the “True” case’s catch block.

    False Case

    Notice that you have RegKey.Name in your log statement, and RegKey is very obviously null because you never set it (it is only set in the True case). I think this is where your error is.

    True Case Catch Block

    The catch block in your “True” case does not access any property of any variable that may be null. However, StartLogFile may itself be failing with such an execption inside.

    Swapped statements

    I have a feeling that you have swapped the two StartLogFile() calls (the False case one should be in the catch block of the True case, and the one in the catch block of the True case should be in the False case).

    Avoid error logging that may itself fail

    Also, even in the True case block, you cannot assume RegKey is non-null because Registry.CurrentUser.OpenSubKey may fail and you’ll not understand where the error is because your try-catch block catches the fault and the it fails on your error logging statement instead! This type of bug can be very frustrating to find, especially in large systems. The morale: never make your error logging code too complex — if they fail, they make it difficult to find out what happened.

    Always include stack trace in error log

    Also, is there any reason why you don’t include a stack trace in your error logging? Having a stack trace will immediately pin-point you to the problem code line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net Windows Service developed in VB.net. I have a settings file
I have a simple windows Service developed in VS.net 2008 and VB.net. When I
I have a very simple windows Service that is developed in vb.net 2008. When
I have developed a Web service using WCF Service Application. This service application is
I have developed a .NET Windows Service (in VS2010) that needs to: Access shared
I have an old ASP.NET web application on a server, which was developed in
I have developed a .NET service and it's been running well on my dev
I have developed a WCF Service Application hosted in IIS 7.5 targeting .NET 3.5
I have developed a windows service using .net . My service makes some calls
We have developed a web service which is consumed fine by a C# .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.