I'm running into a strange issue with Azure Function Apps. Newtonsoft Json.NET deserialization is not liking the $type annotations. My deserialization code looks like:
return JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.Auto
});
The json looks like:
{
"$type": "Trading.Control.Json.TradingConfig, Trading",
"Config": {
"$type": "Trading.Control.Json.Config, Trading",
"Optimize": false
},
"Trading": {
"$type": "System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[Trading.Platforms.Credentials, Trading]], mscorlib",
...
And is serialized with:
return JsonConvert.SerializeObject(o, new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.All,
Formatting = Formatting.Indented
});
The error is:
2017-08-01T17:32:46.395 Type specified in JSON
'Trading.Control.Json.TradingConfig, Trading, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with
'Trading.Control.Json.TradingConfig, Trading, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Path '$type', line 2, position 56.
As you can see, the types appear to be identical. This code is well tested locally and works as expected. It will fail in Azure on the first $type annotation encountered, regardless of how many I remove.
I would like to keep using the annotations, as I need them for deserializing objects derived from an abstract class.
This is compiled in x64, .NET 4.7, Json.NET v10.0.3, Azure Function Apps v1.0.11027.0 (~1). I have the Newtonsoft.Json.dll file in the bin folder, with #r "Newtonsoft.Json.dll" to reference it. Any ideas? Much appreciated.
Edit: I have also tried adding a project.json file looking like:
{
"frameworks": {
"net47":{
"dependencies": {
"Newtonsoft.Json": "10.0.3"
}
}
}
}
which successfully installed. I removed the assembly file I uploaded, and the #r import. The error is now:
2017-08-01T18:30:18.971 Error resolving type specified in JSON 'Trading.Control.Json.TradingConfig, Trading'. Path '$type', line 2, position 56.
I suspect there is a "base namespace" or somesuch lookup error.
The filesystem of the function looks like: /site/wwwroot/TimerTriggerCSharp3/ with assemblies in a bin folder. They are all loaded with #r imports, which work fine.