System.IO.Packaging 使用 OpenXML SDK 的 Azure 函数运行时绑定失败
Azure functions runtime binding failing for System.IO.Packaging using OpenXML SDK
我有一个项目 运行 在 Functions 运行time 的 v1 中作为 Azure Functions 很好,但我正忙于为 v2 重写它并且我被卡住了。
我的 Azure Function 依赖于我的一个库,而这个库又依赖于另一个库。这两个库都依赖于我通过 NuGet 在这些项目中安装的 Open XML SDK。他们都通过 NuGet 安装了 System.IO.Packaging。
如果我通过控制台应用程序 运行 我的代码,它 运行 没问题。当我尝试 运行 它作为 Azure 函数时,它在我的库代码中途运行,但随后函数 运行time 因错误而结束:
System.Private.CoreLib: Exception while executing function: getWorkbook. ExcelGenerator: Could not load file or assembly
'System.IO.Packaging, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file
specified.
我已经尝试将 System.IO.Packaging 添加到 Azure Function 项目(我意识到我不应该这样做)但它随后因新错误而失败:
System.Private.CoreLib: Exception while executing function:
getWorkbook. ExcelGenerator: Could not load type
'System.IO.Packaging.CompressionOption' from assembly 'WindowsBase,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
我怀疑第一个错误中的 0.0.0.0 版本号,我真的不明白第二个错误(或者老实说,为什么将 System.IO.Packaging 添加到 Azure Function 有任何不同,鉴于这只是 运行ning 编译的库代码)。
另一件奇怪的事情是 WindowsBase 没有出现在我的 Azure 函数的 "Assemblies" 依赖项列表中,但它 显示在 "add reference" 对话框。如果我取消选中它,我会收到一个神秘的错误提示 "No assembly reference with the name "{0}" could be found in the project".
我很确定 System.IO.Packaging 或 WindowsBase 无法通过 Azure 部署,但我不确定如何。我很快发现我对 DLL 依赖项的工作方式知之甚少,更不用说在 Azure 中了——有什么想法吗?
要将 v1 函数重写为 v2,请右键单击 Function 项目,然后 Edit FunctionProjectName.csproj
,将 Function 项目的 TargetFramework
更改为 netcoreapp2.1
,将 AzureFunctionsVersion
更改为 [=14] =].
我们可能必须安装 packages for v2 function,因为它们不再像 v1 中那样是内置的。
代码重构是必要的,如果遇到任何汇编问题,请尝试.Net Core控制台应用程序中的代码,看看它是.net core问题还是与Function运行时有关。
如果host.json中有一些配置,需要注意一些格式已经改变。
通常,建议创建模板 v2 功能并将旧内容与新 v2 模板进行比较。
我有一个项目 运行 在 Functions 运行time 的 v1 中作为 Azure Functions 很好,但我正忙于为 v2 重写它并且我被卡住了。
我的 Azure Function 依赖于我的一个库,而这个库又依赖于另一个库。这两个库都依赖于我通过 NuGet 在这些项目中安装的 Open XML SDK。他们都通过 NuGet 安装了 System.IO.Packaging。
如果我通过控制台应用程序 运行 我的代码,它 运行 没问题。当我尝试 运行 它作为 Azure 函数时,它在我的库代码中途运行,但随后函数 运行time 因错误而结束:
System.Private.CoreLib: Exception while executing function: getWorkbook. ExcelGenerator: Could not load file or assembly 'System.IO.Packaging, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
我已经尝试将 System.IO.Packaging 添加到 Azure Function 项目(我意识到我不应该这样做)但它随后因新错误而失败:
System.Private.CoreLib: Exception while executing function: getWorkbook. ExcelGenerator: Could not load type 'System.IO.Packaging.CompressionOption' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
我怀疑第一个错误中的 0.0.0.0 版本号,我真的不明白第二个错误(或者老实说,为什么将 System.IO.Packaging 添加到 Azure Function 有任何不同,鉴于这只是 运行ning 编译的库代码)。
另一件奇怪的事情是 WindowsBase 没有出现在我的 Azure 函数的 "Assemblies" 依赖项列表中,但它 显示在 "add reference" 对话框。如果我取消选中它,我会收到一个神秘的错误提示 "No assembly reference with the name "{0}" could be found in the project".
我很确定 System.IO.Packaging 或 WindowsBase 无法通过 Azure 部署,但我不确定如何。我很快发现我对 DLL 依赖项的工作方式知之甚少,更不用说在 Azure 中了——有什么想法吗?
要将 v1 函数重写为 v2,请右键单击 Function 项目,然后 Edit FunctionProjectName.csproj
,将 Function 项目的 TargetFramework
更改为 netcoreapp2.1
,将 AzureFunctionsVersion
更改为 [=14] =].
我们可能必须安装 packages for v2 function,因为它们不再像 v1 中那样是内置的。
代码重构是必要的,如果遇到任何汇编问题,请尝试.Net Core控制台应用程序中的代码,看看它是.net core问题还是与Function运行时有关。
如果host.json中有一些配置,需要注意一些格式已经改变。
通常,建议创建模板 v2 功能并将旧内容与新 v2 模板进行比较。