Azure / Azure/azure-functions-host

Cannot return "$property": "value" inside context.res.body

Open
#1,569 1 comment 1 reaction 0 assignees View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 10h
Merged PRs (30d)
36

Description

The runtime cannot handle JSON property values with a dollar sign in them when serializing function output to the client.

#### Repro steps

Provide the steps required to reproduce the problem

1. Step A

Build a NodeJS HTTP function that returns something like:

```javascript
context.res = {
status: err ? 500 : 200,
headers: {
'content-type': 'application/json'
},
body: {
results: {"$property": "value"}
}
}
```

2. Step B

Deploy function.

#### Expected behavior

The browser should get a JSON object consisting of `{"results": {"$property": "value"}}`

#### Actual behavior

The runtime crashes inside of Newtonsoft.Json with a JsonSerializationException:

```
2017-06-05T09:31:35.910 Newtonsoft.Json.JsonSerializationException : Error getting value from 'Func' on 'NodejsFunc'. ---> System.InvalidCastException : Unable to cast transparent proxy to type 'Nan.Persistent >*'.
at GetFunc(Object )
at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
End of inner exception
at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer,Object value,JsonContainerContract contract,JsonProperty member,JsonProperty property,JsonContract& memberContract,Object& memberValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer,Object value,JsonObjectContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer,ISerializable value,JsonISerializableContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer,IDictionary values,JsonDictionaryContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer,IDictionary values,JsonDictionaryContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer,IDictionary values,JsonDictionaryContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer,IDictionary values,JsonDictionaryContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer,IEnumerable values,JsonArrayContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer,IDictionary values,JsonDictionaryContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter,Object value,Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter,Object value,Type objectType)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type,Object value,Stream writeStream,Encoding effectiveEncoding)
at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type,Object value,Stream writeStream,Encoding effectiveEncoding)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type,Object value,Stream writeStream,HttpContent content)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type,Object value,Stream writeStream,HttpContent content,TransportContext transportContext,CancellationToken cancellationToken)
at async System.Web.Http.WebHost.HttpControllerHandler.WriteBufferedResponseContentAsync(HttpContextBase httpContextBase,HttpRequestMessage request,HttpResponseMessage response,IExceptionLogger exceptionLogger,IExceptionHandler exceptionHandler,CancellationToken cancellationToken)
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with a NodeJS HTTP function that assigns an object containing "$property" to context.res.body, then inspect the Newtonsoft.Json serialization path shown in the exception. Done means the client receives {"results":{"$property":"value"}} without the runtime crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, node.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.