Solved

System.Guid.NewGuid() created empty guid... why?

Posted on 2010-08-25
4
1,716 Views
Last Modified: 2012-05-10
Dim symbol_guid As Guid = System.Guid.NewGuid()

why when i debug above code i get empty string?
thanks
0
Comment
Question by:JSW21
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 225 total points
ID: 33525089
Use the ToString() method instead?
    Dim symbol_guid As String = System.Guid.NewGuid().ToString
    '                  ^^^^^^                        ^^^^^^^^^

Open in new window

0
 
LVL 1

Assisted Solution

by:Yarx
Yarx earned 225 total points
ID: 33525264
You shouldn't get an empty string if the object type is Guid. I tried the exact same logic and it worked fine for me. However if you're looking to write it out to the screen you'll likely want to display it as a string like mentioned above, but leave it as a Guid for the datatype. It'll make tracking down errors and other problems a lot easier. Also, use Guid.Empty for checking if a Guid is set or not.

The below example is C# but it should give you the jist of it.

//This will give you an empty guid
System.Guid g = new System.Guid();
Write(g == System.Guid.Empty); //will be true

//This will generate a guid and save it to the variable
g = System.Guid.NewGuid();
Write(g == System.Guid.Empty); //will be false

//Use .ToString() when trying to display it.
Write(g.ToString());

Open in new window

0
 
LVL 18

Assisted Solution

by:Anil Golamari
Anil Golamari earned 50 total points
ID: 33525362
vb.net: dim g as string = System.Guid.NewGuid().ToString()

C#: string outputstring = System.Guid.NewGuid().ToString();

You need make the datatype to string as mentioned by Idle_mind
0
 

Author Closing Comment

by:JSW21
ID: 33529118
Actually I Debug it via - Locals window...
The Value is really in Empty...
But when use tostring the value will be shown...

Also i read from other blog it says that it VS2008 bug ... but value are there... only it will not show in debug screen.

Thanks ALL
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question