Azure / Azure/azure-functions-host
AddNewtonsoftJson causes Azure App Service to partially break
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
Source issue: https://github.com/Azure/azure-functions-signalrservice-extension/issues/261
@rockgecko-development
The user tried to customize the newtonsoft json serialization settings of http trigger, but encountered 500 error while called the api, and failed to connect to the log stream.
I reproduced the problem without SignalR trigger but with http trigger, so I think it isn't a problem particular to SignalR trigger. Source codes appended.
The questions are:
>1. Why does AddNewtonsoftJson break it?
>2. What is the right way to set the default UTC date time handling and camel casing serialization for all of my own HttpTrigger functions?
>3. Could there be better error logging for Azure Function Apps that partially fail to initialise, or did I miss somewhere? Part of the problem was the issue prevented me from even viewing Log Streaming.
#### Investigative information
- Function App version: .Net core 3.1.x
- Invocation ID: cannot open log stream
#### Repro steps
1. Invoke the API, got 500 error code.
2. Failed to start a log stream.
#### Known workarounds
delete the startup class.
#### Related information
Provide any related information
* Programming language used: C#
* Bindings used : Http trigger
Source
```cs
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
});
}
}
```
```cs
[FunctionName("http")]
public static ActionResult Index([HttpTrigger] HttpRequest req)
{
return new OkResult();
}
```
```xml
```
Contributor guide
Research direction
Start with the reported Startup.Configure entry point and the AddNewtonsoftJson configuration, then reproduce the HTTP trigger's 500 response and failed log stream using the supplied package versions. Done means identifying why this configuration partially prevents the Function App from initializing, documenting the supported serialization configuration, and clarifying whether additional initialization errors can be exposed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100