Quantcast
Viewing all articles
Browse latest Browse all 275

Sitecore.Data.ID The call is ambiguous

In Sitecore you cannot compare an ID with NULL; it will produce the following error:

The call is ambiguous between the following methods or properties: ‘Sitecore.Data.ID.operator ==(Sitecore.Data.ID, Sitecore.Data.ID)’ and ‘Sitecore.Data.ID.operator ==(Sitecore.Data.ID, Sitecore.Data.ShortID)’

I.e. the following code is invalid:

Sitecore.Data.ID someID = GetSomeID();
if (someID == null)
{
  // do code
}

Instead, you need to call Sitecore.Data.ID.IsNullOrEmpty():

ID someID = GetSomeID();
if (Sitecore.Data.ID.IsNullOrEmpty(someID))
{
  // do code
}

A quick tip for you.


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 275

Trending Articles