Guid is all 0's (zeros)?
Solution 1:
Use the static method Guid.NewGuid()
instead of calling the default constructor.
var responseObject = proxy.CallService(new RequestObject
{
Data = "misc. data",
Guid = Guid.NewGuid()
});
Solution 2:
Lessons to learn from this:
1) Guid is a value type, not a reference type.
2) Calling the default constructor new S()
on any value type always gives you back the all-zero form of that value type, whatever it is. It is logically the same as default(S)
.
Solution 3:
Try this instead:
var responseObject = proxy.CallService(new RequestObject
{
Data = "misc. data",
Guid = new Guid.NewGuid()
});
This will generate a 'real' Guid value. When you new a reference type, it will give you the default value (which in this case, is all zeroes for a Guid).
When you create a new Guid, it will initialize it to all zeroes, which is the default value for Guid. It's basically the same as creating a "new" int (which is a value type but you can do this anyways):
Guid g1; // g1 is 00000000-0000-0000-0000-000000000000
Guid g2 = new Guid(); // g2 is 00000000-0000-0000-0000-000000000000
Guid g3 = default(Guid); // g3 is 00000000-0000-0000-0000-000000000000
Guid g4 = Guid.NewGuid(); // g4 is not all zeroes
Compare this to doing the same thing with an int:
int i1; // i1 is 0
int i2 = new int(); // i2 is 0
int i3 = default(int); // i3 is 0