Solved

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

Posted on 2010-08-25
4
1,689 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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