-5

I faced with a strange problem.

VB.NET - not working

Dim stringData As String = Encoding.UTF8.GetString(buffer, 0, buffer.Length)    
If Not [String].IsNullOrEmpty(stringData) AndAlso System.IO.File.Exists(stringData) Then
    Process.Start(stringData)
End If 

Working

  If Not [String].IsNullOrEmpty(stringData) AndAlso System.IO.File.Exists(stringData) Then
      Process.Start(stringData)
End If
 Process.Start(stringData)

C# - working:

string stringData = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

if (!String.IsNullOrEmpty(stringData) && System.IO.File.Exists(stringData))
{
    Process.Start(stringData);
}

Can anyone explain me what am I doing wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Alexander
  • 691
  • 1
  • 11
  • 29
  • 3
    I am not sure but this _seems_ like a human problem. Are you sure the file path is the _exact_ same? – Alex Booker Jul 23 '15 at 18:07
  • 1
    Put in a break point and check what the `stringData` variable is for each code base. – Thraka Jul 23 '15 at 18:09
  • Have you tried debugging ? Did you tried executing it without using a string variable ? i.e: `Process.Start(@"Full-Path")` – Orel Eraki Jul 23 '15 at 18:09
  • 3
    How is it "not working"? If it doesn't launch the program, check for exceptions. Perhaps you're using a relative path that's correct for the C# compiled EXE, but the VB.NET compiled EXE (that is say, in a different location) the path isn't valid anymore. – Chris Sinclair Jul 23 '15 at 18:10
  • 3
    And "Working - Not Working" stands for... – Josh Part Jul 23 '15 at 18:10
  • I've edited. Check it plz. – Alexander Jul 23 '15 at 18:11
  • is string data a partial path? – Daniel A. White Jul 23 '15 at 18:12
  • What exactly is the error? My first thought would be to reverse the order of your if statement in VB, so that it short circuits on the IsNull. – Michael McPherson Jul 23 '15 at 18:12
  • stringData - it's a full path. – Alexander Jul 23 '15 at 18:14
  • 2
    @Alexander I suspect that in the VB version your buffer is one byte larger than you intend. In C# you give the number of elements in an array when declaring it, whereas in VB you give the index of the last element. – Andrew Morton Jul 23 '15 at 18:14
  • 1
    Andrew Morton's comment may be insightful, but it would help to provide more information about what exactly is going on. Is it throwing an exception, for instance? If so, what does the exception say? ...Also you should be able to forgo using `[]` around `String`.........As a matter of fact, that may also be your problem (I think that may change it into an identifier name - I could be wrong), but we just need more specific information. – Panzercrisis Jul 23 '15 at 18:21

1 Answers1

1

Try this way:

Dim stringData As String = GetFolderPath(SpecialFolder.MyDocuments) & "\my.exe" 'For example

            If Not String.IsNullOrEmpty(stringData) Then

                If File.Exists(stringData) Then

                    Process.Start(stringData)

                Else

                    MsgBox("File couldn't be found.", vbCritical, "MyApp")

                End If

            End If