[英]Azure Function V3 Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=3.1.6.0
[英]Azure function v4 migration. Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral
我目前正在將 Azure Function 從 v2 遷移到Azure Functions v4 。 我已經將我的項目遷移到.NET6並修復了所有 package 引用錯誤。 我在解決方案中有 3 個項目,我將它們調整為.NET6 和 Azure Function v4 。 為此,我編輯了每個項目的 .csproj 文件,並升級/替換了不適用於 .NET6 的包。 每個項目的項目文件如下所示:
Azure Function 項目:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCM.1.z\x.1.z.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="2.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="1.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="3.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
第二個項目:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Devices" Version="1.38.2" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.80" />
<PackageReference Include="Twilio" Version="6.0.1" />
<PackageReference Include="UnitsNet" Version="4.149.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\x.1.w\x.1.w.csproj" />
</ItemGroup>
</Project>
第三個項目:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
</ItemGroup>
</Project>
當我構建項目時,沒有出現任何錯誤。 但是當我調試項目時,出現了一個異常,如下所示:
例外:
拋出異常:Microsoft.Azure.WebJobs.Host.dll 中的“System.IO.FileNotFoundException”。 Microsoft.Azure.WebJobs.Host.dll 中出現類型為“System.IO.FileNotFoundException”的異常,但未在用戶代碼中處理無法加載文件或程序集“Microsoft.Extensions.Configuration.Abstractions,版本=7.0.0.0,文化 = 中性,PublicKeyToken = adb9793829ddae60'。
我在過去兩周嘗試了不同的包,因為當我用谷歌搜索這個錯誤時,建議是查看package不支持哪些包: <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
。 我分析了我所有的包裹。 將它們改回並強制我仍然遇到相同的錯誤。
誰能幫我說說我到底要改變什么?
正如@Codebrane 所說, Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0
7.0.0.0 在使用 Azure Functions v4 版本時存在問題,它已在該線程中得到實際展示。
嘗試將Microsoft.Extensions.Configuration.Abstractions
降級到Version 6.0.0
並檢查。
Microsoft.NET.Sdk.Functions
依賴於 NuGet 與代碼相關的包,但這些可以由 VS IntelliSense 建議並自動安裝,或者它顯示需要這些包。
此外,NuGet 包在 Azure 函數中的進程內和進程外工作人員類型之間有所不同。 有關更多信息,請參閱我的主題之一。
我正在構建一個 Azure function 作為net6
中的v4
。 因為我在啟動System.IO.FileNotFoundException
時也得到了關於庫Microsoft.Extensions.Configuration.Abstraction 7.0.0
的 System.IO.FileNotFoundException,所以我降級到Microsoft.Extensions.Configuration.Abstractions 6.0.0
並且還不得不降級其他依賴項,例如Microsoft.EntityFrameworkCore
到6.0.12
並且,因為我使用 PostgreSQL 也Npgsql.EntityFrameworkCore.PostgreSQL
到6.0.8
。 現在一切正常。
我通過包含 package Microsoft.Extensions.Configuration.Abstractions 6.0.0
並構建它來修復它。 包含這個 package 並不能直接解決問題,它只是顯示哪些包有沖突。 通過降級這些沖突的包,可以調試項目。 要檢查哪些包有沖突,您必須在 visual studio 中打開右側的包,然后查看感嘆號在哪里。 然后你必須分析這些包以了解你必須降級它們的版本。 它因項目而異。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.