question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operator '??' cannot be applied to operands of type 'Guid' and 'string'

See original GitHub issue

When generating C# against an API that takes an array of guid on the query string, autorest outputs code that fails to compile

foreach (var _item in ids)
{
    _queryParameters.Add(string.Format("ids={0}", System.Uri.EscapeDataString(_item ?? string.Empty)));
}

_item ?? string.Empty causes

CS0019 Operator ‘??’ cannot be applied to operands of type ‘Guid’ and ‘string’

Seems to be the same root issue as #1648

The below swagger causes a repro on 1.0.0-Nightly20170212

{
    "swagger": "2.0",
    "info": {
        "version": "1.0",
        "title": "title"
    },
    "host": "localhost",
    "schemes": ["http"],
    "paths": {
        "/test": {
            "delete": {
                "tags": ["test"],
                "operationId": "deleteTest",
                "consumes": [],
                "produces": [],
                "parameters": [{
                    "name": "ids",
                    "in": "query",
                    "required": true,
                    "type": "array",
                    "items": {
                        "type": "string",
                        "format": "uuid",
                        "x-nullable": false
                    },
                    "collectionFormat": "multi",
                    "x-nullable": true
                }],
                "responses": {
                    "204": {
                        "description": "No Content"
                    }
                }
            }
        },
    },
    "definitions": {

    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chsienkicommented, May 3, 2017

This is still broken with the latest fix. the _item?.ToString() fails when _item is a Guid, because it’s a value type.

0reactions
fearthecowboycommented, Apr 28, 2017

Hmm. I may have found the fix. gimme a moment…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Operator '==' cannot be applied to operands of type 'System ...
but ToString() doesn't exist in Linq to Entities. The answer to this question - Problem getting GUID string value in Linq-To-Entity query - ......
Read more >
cannot be applied to operands of type 'string' and 'System.Guid'
Compiler Error Message: CS0019: Operator '==' cannot be applied to operands of type 'string' and 'System.Guid' Source Error: ...
Read more >
Operator '==' cannot be applied to operands of type 'System ...
Coding example for the question Operator '==' cannot be applied to operands of type 'System.Guid' and 'string' in linq to entity-LINQ,C#.
Read more >
Operator '==' cannot be applied to operands of type 'string' and ...
Solution 2. There is not much to add since the error message allready says it all... You can no compare a String with...
Read more >
Operator '+' cannot be applied to operands of type 'Guid' and ...
As others have said, you need to call ToString() to concatenate. However, I'd also like to suggest using string interpolation which will call ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found