tags:

views:

32

answers:

3

Hi I have a project that was created in a previous version to 3.5. I since then ran the wizard to upgrade it to 3.5. After I did this I built the project but it has an error. The error is that a Guid is trying to access the properties HasValue and Value:

if(theGuid.HasValue)
{
    id = theGuid.Value
}

The errors are 'System.Guid' does not contain a definition for 'HasValue' and no extension method 'HasValue' accepting a first argument of type 'System.Guid' could be found (are you missing a using directive or an assembly reference?)

The error is similiar for the Value property.

Can someone please tell me what's going on? Is it a property that was taken out of the framework? If so what could I replace it with?

Thanks!

+1  A: 

Nullable types are still possible in 3.5.

Are you sure theGuid is a Guid? type and not just Guid?

Brandon
+1  A: 

It sounds like "theGuid" should have been defined as:

Guid? theGuid;

And now, for some reason, it isn't using Nullable<T> in its definition, and is rather defined as:

Guid theGuid;
Reed Copsey
Thanks, this is the case. I checked source control which contains before the conversion and it is a nullable type. After conversion it seems a lot of nullable types have become nonnullable. I don't know why this should have happened though.
Mr Cricket
@Mr Cricket: It shouldn't have really happened as part of the conversion. That's a fairly odd conversion issue.
Reed Copsey
+1  A: 

HasValue and Value are properties of the Nullable<T> struct.

So you code should work if theGuid was declared as nullable Guid:

Guid? theGuid = //...
Guid id;

if (theGuid.HasValue)
{
    id = theGuid.Value;
}
dtb