Azure Function v2 引用了 Newtonsoft.Json 高于 Microsoft.NET.Sdk.Functions 版本的项目
Azure Function v2 references a project with a higher version of Newtonsoft.Json than Microsoft.NET.Sdk.Functions
我正在编写 v2 Azure Durable Function。将 C# 对象传递给辅助 activity 函数时,我在用于序列化所传递类型的自定义 JsonConverter
中遇到运行时错误。自定义 JsonConverter
位于必须引用 Newtonsoft.Json 12.x 的库中,而 Microsoft.NET.Sdk.Functions 被锁定到 11.0.2.
jObject error CS1705: Assembly 'ContractLibrary' with identity 'ContractLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher version than referenced assembly 'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
我相信 GitHub Issue is relevant. This comment 关于那个问题似乎表明添加 Newtonsoft.Json 12.x 作为函数项目的直接依赖项可能会有所帮助。这对另一个 Function 项目有帮助,但现在我又碰壁了。我能做些什么来缓解这种情况吗?
您可以尝试的一件事是绕过 Durable Functions 使用的序列化逻辑并进行您自己的序列化。例如,而不是这样做:
public static void MyFunc([ActivityTrigger] MyCustomType input)
{
// ...
}
尝试这样做:
public static void MyFunc([ActivityTrigger] JObject json)
{
// manually convert the JObect into MyCustomType
}
如果这对你有帮助,请告诉我。
我正在编写 v2 Azure Durable Function。将 C# 对象传递给辅助 activity 函数时,我在用于序列化所传递类型的自定义 JsonConverter
中遇到运行时错误。自定义 JsonConverter
位于必须引用 Newtonsoft.Json 12.x 的库中,而 Microsoft.NET.Sdk.Functions 被锁定到 11.0.2.
jObject error CS1705: Assembly 'ContractLibrary' with identity 'ContractLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher version than referenced assembly 'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
我相信 GitHub Issue is relevant. This comment 关于那个问题似乎表明添加 Newtonsoft.Json 12.x 作为函数项目的直接依赖项可能会有所帮助。这对另一个 Function 项目有帮助,但现在我又碰壁了。我能做些什么来缓解这种情况吗?
您可以尝试的一件事是绕过 Durable Functions 使用的序列化逻辑并进行您自己的序列化。例如,而不是这样做:
public static void MyFunc([ActivityTrigger] MyCustomType input)
{
// ...
}
尝试这样做:
public static void MyFunc([ActivityTrigger] JObject json)
{
// manually convert the JObect into MyCustomType
}
如果这对你有帮助,请告诉我。