views:

2663

answers:

5

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.

+2  A: 

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

abatishchev
+1  A: 

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?

TGnat
A: 

Dim g As New Guid(Guid.NewGuid().ToString)

i still get an empty guid! I give up.

+5  A: 

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

A: 

Try this

Dim g As New Guid();

Dim whereDoYouWantToSeeIt As String = g.ToString();