Operator '??' cannot be applied to operands of type 'Guid' and 'string'
See original GitHub issueWhen 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:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is still broken with the latest fix. the _item?.ToString() fails when _item is a Guid, because it’s a value type.
Hmm. I may have found the fix. gimme a moment…