Guid 全是 0(零)? [英] Guid is all 0's (zeros)?

查看:32
本文介绍了Guid 全是 0(零)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一些使用 Guid 来回发送对象的 WCF 服务.在我的网络应用测试代码中,我正在执行以下操作:

I'm testing out some WCF services that send objects with Guids back and forth. In my web app test code, I'm doing the following:

var responseObject = proxy.CallService(new RequestObject
{
    Data = "misc. data",
    Guid = new Guid()
});

出于某种原因,对 new Guid() 的调用正在生成像这样全为 0(零)的 Guid:

For some reason, the call to new Guid() is generating Guids with all 0's (zeros) like this:

00000000-0000-0000-0000-000000000000

这可能是什么原因造成的?

What could be causing this?

推荐答案

使用静态方法 Guid.NewGuid() 而不是调用默认构造函数.

Use the static method Guid.NewGuid() instead of calling the default constructor.

var responseObject = proxy.CallService(new RequestObject
{
    Data = "misc. data",
    Guid = Guid.NewGuid()
});

这篇关于Guid 全是 0(零)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆