Question

I have a Guid.NewGuid() call that is creating an Empty Guid.

What would cause such a problem and how can I fix it?

Edit: The code:

<WebMethod()> _
Public Function CreateRow(rowValue As String) as String
    Dim rowPointer As Guid = System.Guid.NewGuid()
    Dim rowPointerValue As String = rowPointer.ToString()

    Try
        Dim result as Integer = SqlHelper.ExecuteNonQuery(ConnectionString, "Sproc_Name", rowValue, rowPointer)

        Return result
    Catch ex as Exception
        Throw ex
    End Try
End Function

Edit: Turns out that rowPointer was originally being passed to the SqlHelper and not rowPointerValue - This of course is passed as empty, as pointed out in the answers. Changing it to rowPointerValue/rowPointer.ToString() fixed the problem.

Was it helpful?

Solution

This is an old problem in VB.NET. It is only the debug visualizer that is broken.

http://www.thesoftwaredevotional.com/2008/12/guid-visualizer-broken-in-vbnet.html

OTHER TIPS

I had the same thing. Debugging of Guid.NeGuid() was showing that it's empty. Calling .ToString() fixed the situation.

I tested this code in VS2008 and the results are not what I expected. It seems that the new guid is not created until the toString method is called. After stepping through the code rowPointerValue does hold a string representation of the guid.

It seems to be using defferred execution?

I've only experiened this problem in VB.NET and only while debugging. Thanks 48494, for that info.

Try this

Dim g As New Guid();

Dim whereDoYouWantToSeeIt As String = g.ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top