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.

Error while deserializing function with nullable return to xml

See original GitHub issue

Hi,

Autorest generated classes won’t compile when generating this json function:

"/api/DataManager/DoesTechnologyNameExistsInBrand": {
  "post": {
    "tags": [
      "DataManager"
    ],
    "operationId": "DataManager_DoesTechnologyNameExistsInBrand",
    "consumes": [
      "application/json",
      "text/json",
      "application/xml",
      "text/xml",
      "application/x-www-form-urlencoded"
    ],
    "produces": [
      "application/json",
      "text/json",
      "application/xml",
      "text/xml"
    ],
    "parameters": [
      {
        "name": "technologyName",
        "in": "query",
        "required": true,
        "type": "string",
        "x-nullable": true
      },
      {
        "name": "brandId",
        "in": "query",
        "required": true,
        "type": "integer",
        "format": "int32",
        "x-nullable": false
      },
      {
        "name": "technology",
        "in": "body",
        "required": true,
        "schema": {
          "$ref": "#/definitions/tblTechnology"
        }
      }
    ],
    "responses": {
      "200": {
        "description": "OK",
        "schema": {
          "type": "boolean",
          "x-nullable": false
        }
      }
    }
  }
},

This fragment:

bool? _tmp_ = null;
                    if (_httpResponse.Content.Headers.ContentType.MediaType == "application/xml" &&
                        XmlSerialization.Root(XmlSerialization.ToDeserializer(e => (bool)e))(System.Xml.Linq.XElement.Parse(_responseContent), out _tmp_))
                    {
                        _result.Body = _tmp_;
                    }
                    else
                    {
                        _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<bool?>(_responseContent, Client.DeserializationSettings);
                    }

Generates an error:

Argument 2: cannot convert from ‘out bool?’ to ‘out bool’

Because out _tmp is bool but the variable is declared as bool?.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
HowardvanRooijencommented, Mar 29, 2017

I’m experiencing the same problem - although it’s not just generating the same non-compiling method above - it’s also generating a missing method:

internal static LocalizedContentRequest XmlDeserialize(XElement payload)
{
    var result = new LocalizedContentRequest();
    var deserializeLocalizedContent = XmlSerialization.CreateListXmlDeserializer(XmlSerialization.ToDeserializer(e => LocalizedContent.XmlDeserialize(e)), null);
    IList<LocalizedContent> resultLocalizedContent;
    if (deserializeLocalizedContent(payload, "LocalizedContent", out resultLocalizedContent))
    {
        result.LocalizedContent = resultLocalizedContent;
    }
    return result;
}

Where .XmlDeserialize(e) in LocalizedContent.XmlDeserialize(e) doesn’t exist.

If XML support is only for a specific scenario, is it not possible to turn it off by default and enable by configuration switch?

The added complexity I have is that one of my operations has to return an XML document (it’s a signed XML document) - which seems to trigger this behaviour.

0reactions
olydiscommented, Sep 27, 2017

This is off by default now. Please reopen or post a new issue if you encounter related issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can XmlSerializer.Deserialize ever return null? - Stack Overflow
Yes, Deserialize can return null when the input does not contain the XML that is expected. This is frequently seen when there is...
Read more >
XmlSerializer.Deserialize Method (System.Xml.Serialization)
Deserializes an XML document contained by the specified XmlReader and allows the overriding of events that occur during deserialization.
Read more >
XML Serializer object's property retuns null - Unity Forum
I am trying to create a data class from a xml file . it's work great on <Object> element and it give me...
Read more >
Getting null in nested elements when deserializing xml-C
Your deserialization fails because, in the sample XML, these elements are not in any namespace. Why is this happening? It's because all your...
Read more >
The Serializer Component (Symfony Docs)
Converting Property Names when Serializing and Deserializing ... DateTime $createdAt; // Getters public function getAge(): int { return $this->age; } ...
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