Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now