-2

I have a problem with Guid using c#, in my application, all field of type GUID were returned '{00000000-0000-0000-0000-000000000000}'.

How do I can to resolve the problem?

If need, I would put code.

plalx
  • 42,889
  • 6
  • 74
  • 90
  • All zeros is valid Guid - so not sure what your problem is. Clearly you know how to create one - search https://www.bing.com/search?q=c%23+create+guid immediately gives http://stackoverflow.com/questions/2344098/c-sharp-how-to-create-a-guid-value. So please clarify what you have problem with so it can be answered. – Alexei Levenkov Feb 24 '16 at 00:25
  • That represents `Guid.Empty`. You haven't shown us your code but you've obviously not set the guid. You need to use `Guid.NewGuid()`. – Rob Feb 24 '16 at 04:06

2 Answers2

4

The default value of Guid is {00000000-0000-0000-0000-000000000000} As I consider you are using constuctor of Guid and you are getting a default value of Guid.

 var g = new Guid();

In this example g equals to the default value of guid and equals {00000000-0000-0000-0000-000000000000}.

In order to generate guidyou should use Guid.NewGuidmethod.

var g = Guid.NewGuid();
Valentin
  • 5,380
  • 2
  • 24
  • 38
0

You need to use NewGuid method

Guid.NewGuid()

As per msdn

This is a convenient static method that you can call to get a new Guid. The method wraps a call to the Windows CoCreateGuid function. The returned Guid is guaranteed to not equal Guid.Empty.

Abhinav Galodha
  • 9,293
  • 2
  • 31
  • 41
  • This is exactly the same as http://stackoverflow.com/questions/2344098/c-sharp-how-to-create-a-guid-value ... Not sure why you think it solves problem OP has in new way (and missing description of problem too). – Alexei Levenkov Feb 24 '16 at 00:26