我有一个Azure函数,反序列化主题中的消息:
#r "Lib.PosLog.dll"
#r "Newtonsoft.Json"
#r "Microsoft.ServiceBus"
using System;
using System.Threading.Tasks;
using System.Configuration;
using Microsoft.ServiceBus.Messaging;
using Newtonsoft.Json;
using Lib.PosLog;
using System.Reflection;
public static void Run(string message, TraceWriter log)
{
var settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
};
var transaction = JsonConvert.DeserializeObject<TransactionDomainSpecific>(message, settings);
}
Run Code Online (Sandbox Code Playgroud)
该消息依赖于自定义DLL Lib.PosLog中的类型:
"$type":"Lib.PosLog.SaleBase, Lib.PosLog",
Run Code Online (Sandbox Code Playgroud)
DeserializeObject函数失败,出现以下内部异常:
InnerException:
HResult=-2146233088
Message=Could not load assembly 'Lib.PosLog'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(TypeNameKey typeNameKey)
at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(TKey key)
at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType(String assemblyName, String typeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, …Run Code Online (Sandbox Code Playgroud)