0

I've created a Windows Application using VB.Net that uses Sub Main to determine if the application should run a specific process or just open as a form for user interaction. Everything works great except for when I try to schedule my application via Windows Task Scheduler. I kept getting the result code of 0xFF. I then tried running my application directly through the command prompt. When doing this, I received a System.ArgumentNullException error. The other information provided is very lacking so I'm struggling to determine where my issue actually lies. I can run my application from the form using a System.Diagnostics.Process command and passing the arguments to it that way. I can also successfully run it by entering command line arguments in the Debug tab of the application Properties. Below is a general outline of what my code looks like. I'm using the Command Line Parser Library to decipher the arguments. Any help or guidance would be greatly appreciated

Imports CommandLine
Imports CommandLine.Text

Module Startup

    Public Sub Main()
        Dim Args() As String = Environment.GetCommandLineArgs
        Dim Options As New Arguments
        Dim Parser As New Parser

        If Parser.ParseArguments(Args, Options) Then
          ' Run application
        Else
          ' Open windows form
        End If
    End Sub

    Public Class Arguments
        <[Option]("p", "process", Required:=True)> Public Property ProcessOption As String
        <[Option]("r", "run", Required:=True)> Public Property RunOption As String
        <[Option]("d", "date", Required:=False, DefaultValue:=Nothing)> Public Property DateOption As Date
        <[Option]("u", "user", Required:=False, DefaultValue:="")> Public Property UserOption As String
    End Class

End Module
  • Add some error handling and log the exception ('ex.ToString()') to the application event log. This will let you find out what exactly is causing the problem (or at least where exactly it is occurring). The error is most likely within the parser library (which I guess is this: https://commandline.codeplex.com/). The library seems overkill IMO but meh. Without a stack trace I dont know! – Sam Makin Aug 07 '17 at 20:52
  • You should clarify the title. a `Null Exception` as in the title, usually means a NullReferenceException, not an ArgumentNullException – Ňɏssa Pøngjǣrdenlarp Aug 07 '17 at 22:08
  • @Plutonix Thank you. Title has been updated. – Shaun Vetovich Aug 07 '17 at 22:24
  • @SamMakin I will try to add some error handling tomorrow and see what I capture. Thanks! – Shaun Vetovich Aug 07 '17 at 22:24

1 Answers1

0

I was able to run this on my testing machine with a debugger and found where my issue is. It actually has nothing to do with the arguments being passed by the command prompt. It's with another sub call I make. I will have to play with it and if I can't figure it out I will open another question. Thank you for your help.