Solved

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

Posted on 2010-08-25
4
1,809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

635 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