I've spent 10+ hours investigating this issue and at this point I feel like it's a bug.
Here's the setup:
I have a function app MyFunctionApp.csproj which references a project MyDataContracts.csproj that I need to use for serializing/deserializing messages.
Currently I'm using Json.net for serializing/deserializing.
I can demonstrate that there are problems when trying to deserialize JSON to a type in MyDataContracts, even though I can demonstrate that MyDataContracts.dll is loaded:
// MyClass is from MyDataContracts
MyClass instance = new MyClass(); // good so far … interesting ...
Type type = instance.GetType();
Assembly assembly = type.Assembly;
log.Info($"Type {type} comes from assembly '{assembly.FullName}', location = '{assembly.Location}'");
// 2018-06-28T14:39:40.630 [Info] Instance of MyDataContracts.MyClass comes from assembly MyDataContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', location = 'D:\local\Temporary ASP.NET Files\root\48e7c30a\5fd0f557\assembly\dl3\9681789a\c5d216c9_9f0ed401\MyDataContracts.dll'
string json = JsonConvert.SerializeObject(type, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
ypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
log.Info($"Successfully serialized the {type.GetType()}");
// Successfully serialized the System.RuntimeType
log.Info(json);
// "MyDataContracts.MyClass, MyDataContracts, Version=10.0.0, Culture=neutral, PublicKeyToken=null"
// BOOM! This won't work.
type = JsonConvert.DeserializeObject<Type>(json, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
// 2018-06-28T14:39:40.689 [Info] Newtonsoft.Json.JsonSerializationException
// 2018-06-28T14:39:40.689 [Info] Error converting value "MyDataContracts.MyClass, MyDataContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" to type 'System.Type'. Path '', line 1, position 102.
Error converting value "MyDataContracts.MyClass, MyDataContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" to type 'System.Type'. Path '', line 1, position 102.I think you're trying to cast an instance to a Type