Home icon indicating copy to clipboard operation
Home copied to clipboard

Cannot compare Guid to Guid.Empty

Open dcyonce opened this issue 1 year ago • 2 comments

Target name(s)

ESP32-S3

Firmware version

1.12.4.187

Was working before? On which version?

No response

Device capabilities

No response

Description

Cannot compare a Guid to Guid.Empty

None of the following work for various reasons. some are compile errors, some generate System.NullReferenceException: Exception was thrown: System.NullReferenceException

_CurrentTripGUID == Guid.Empty _CurrentTripGUID.Equals(Guid.Empty) _CurrentTripGUID.Equals((object)Guid.Empty _CurrentTripGUID.CompareTo((object)Guid.Empty) == 0

We desperately need a method to see if a Guid is == Guid.Empty

How to reproduce

Try any of these lines of code

private static Guid _CurrentTripGUID;

_CurrentTripGUID == Guid.Empty _CurrentTripGUID.Equals(Guid.Empty) _CurrentTripGUID.Equals((object)Guid.Empty _CurrentTripGUID.CompareTo((object)Guid.Empty) == 0

Expected behaviour

I would expect all of these lines to function:

_CurrentTripGUID == Guid.Empty _CurrentTripGUID.Equals(Guid.Empty) _CurrentTripGUID.CompareTo(Guid.Empty) = 0

Screenshots

No response

Aditional information

No response

dcyonce avatar Jul 23 '25 02:07 dcyonce

A workaround for now: Convert both Guids to strings first and then compare the strings.

_CurrentTripGUID.ToString() == Guid.Empty.ToString()

But, if you need to compare 2 Guids and either one could be Empty ... it gets complicated. Since "G1.CompareTo(G2)" will generate a "Null reference error" if either Guid is Empty, you must compare them both using the ToString() equivalent of each Guid to the string equivalent to Guid.Emtpy first !!

Comparing two Guids, G1 & G2

if ((G1.ToString() == Guid.Empty.ToString()) || (G2.ToString() = Guid.Empty.ToString()) || (G1.CompareTo(g2) != 0))

dcyonce avatar Jul 23 '25 02:07 dcyonce

Fully fixed in develop branches. Available in preview nuget and fw.

josesimoes avatar May 11 '26 15:05 josesimoes