Azure函数3到4升级错误:在外部启动类中配置服务时出错

fv2wmkja  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(151)

我在更新功能应用程序的启动过程中收到以下错误。
AZFD 0005诊断事件错误代码AZFD 0005级别错误消息在外部启动类中配置服务时出错。详细信息Microsoft.Azure.WebJobs.Script.ExternalStartupException:在外部启动类中配置服务时出错。-> System.IO.FileNotFoundException:未能加载文件或程序集“Microsoft.Extensions.Identity.Core,Version=7.0.0.0,Culture=neutral,PublicKeyToken= adb 9793829 ddae 60”。系统找不到指定的文件。在SkyNav.API.Extensions.RegisterServices.AddCustomServices(IServiceCollection服务),位于/Users/mrogers/_AzureDevOps/SkyNavAPI/src/SkyNav. API/Extensions/RegisterServices. cs:87在SkyNav.API.Helpers.Startup.Configure(IWebJobsBuilder构建器)在/Users/mrogers/AzureDevOps/SkyNavAPI/src/SkyNav.API/Helpers/Startup.cs:15在Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureStartup(IWebJobsStartup启动,WebJobsBuilderContext上下文,IWebJobsBuilder构建器),位于D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:166在Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureAndLogUserConfiguredServices(IWebJobsStartup启动、WebJobsBuilderContext上下文、IWebJobsBuilder生成器、ILoggerFactory loggerFactory),位于D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:130在Microsoft.Azure.WebJobs.WebJobsBuilderExtensions. WebJobsStartup(IWebJobsBuilder builder,Type startupType,WebJobsBuilderContext context,ILoggerFactory loggerFactory)位于D:\a_work\1\s\src\Microsoft.Azure.WebJobs.Host\Hosting\WebJobsBuilderExtensions.cs:115在Microsoft.Azure.WebJobs.WebJobsBuilderExtensions. WebJobsBuilderExtensions.cs上的ExternalStartup(IWebJobsBuilder builder、IWebJobsStartupType、StartupTypeException、WebJobsBuilderContext上下文、ILoggerFactory loggerFactory):213,位于Microsoft.Azure.WebJobs.Script.ScriptHostBuilderExtensions.<>c__DisplayClass7_0.b__1(HostBuilderContext上下文,IWebJobsBuilder webJobsBuilder),位于//src/WebJobs. Script/ScriptHostBuilderExtensions.cs:226内部异常结束
这是csproj文件

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
 
  <ItemGroup>
    <None Remove="Newtonsoft.Json" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="11.0.1" />
    <PackageReference Include="Google.Apis.Auth" Version="1.62.0" />
    <PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
      <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
    <PackageReference Include="MongoDB.Driver" Version="2.21.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="SendGrid" Version="9.28.1" />
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.21" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SkyNav.Core\SkyNav.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

下面是Startup.cs代码

using AutoMapper;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using xxxxxx.API.Extensions;
using xxxxxx.API.Helpers;
using xxxxxx.API.Mappers;

[assembly: WebJobsStartup(typeof(Startup))]
namespace xxxxxx.API.Helpers
{
    public class Startup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            builder.Services.AddCustomServices();
        }
    }
}

下面是添加customservices的代码

using AutoMapper;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using xxxxxx.API.Entities;
using xxxxxx.API.Interfaces;
using xxxxxx.API.Mappers;
using xxxxxx.API.Services;
using xxxxxx.Core.Identity;
using xxxxxx.Core.Repository;

namespace xxxxxx.API.Extensions
{
    public static class RegisterServices
    {
        public static IServiceCollection AddCustomServices(this IServiceCollection services)
        {
            #region Service
            services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));

            services.AddScoped<IAuthorizedService, AuthorizedService>();

            services.AddScoped<ITourService, TourService>();

            services.AddScoped<IUserService, UserService>();

            services.AddScoped<ICustomerService, CustomerService>();

            services.AddScoped<IBlobService, BlobService>();

            services.AddScoped<ILogService, LogService>();

            services.AddScoped<ISceneService, SceneService>();

            services.AddScoped<IMediaService, MediaService>();

            services.AddScoped<IHotspotService, HotspotService>();

            services.AddScoped<IExportJsonService, ExportJsonService>();

            services.AddScoped<IIconsService, IconsService>();

            services.AddScoped<ITourModifiedService, TourModifiedService>();

            services.AddScoped<IIndexService, IndexService>();

            services.AddScoped<ICustomerPermissionService, CustomerPermissionService>();

            services.AddScoped<IAuditService, AuditService>();

            services.AddScoped<ITourGroupService, TourGroupService>();

            services.AddScoped<IMediaGroupService, MediaGroupService>();

            services.AddScoped<ISceneVariantService, SceneVariantService>();

            services.AddScoped<IMailService, MailService>();

            services.AddHttpClient();

            services.AddScoped(typeof(IPasswordHasher<User>), typeof(PasswordHasher<>));

            #endregion

            #region Mapper
            services.AddAutoMapper(typeof(UserMapper).Assembly);

            services.AddAutoMapper(typeof(CustomerMapper).Assembly);

            services.AddAutoMapper(typeof(ImageMapper).Assembly);

            services.AddAutoMapper(typeof(LogMapper).Assembly);

            services.AddAutoMapper(typeof(TourMapper).Assembly);

            services.AddAutoMapper(typeof(SceneMapper).Assembly);

            services.AddAutoMapper(typeof(MediaMapper).Assembly);

            services.AddAutoMapper(typeof(HotspotMapper).Assembly);

            services.AddAutoMapper(typeof(TourGroupMapper).Assembly);

            services.AddAutoMapper(typeof(MediaGroupMapper).Assembly);

            #endregion

            return services;
        }
    }
}

我已经检查了所有的直接依赖关系和传递依赖关系,从我所能做的,没有依赖于微软的。扩展。身份。核心版本7.0.0。
此外,该项目的目标框架是.net6.0微软。扩展。身份。核心7.0.0不应该是必需的,也不应该链接到。

7bsow1i6

7bsow1i61#

要解决此错误,请安装Microsoft.Extensions.Identity.Core版本6.0.0

我在我的.NET 6.0V4 Functions Runtime中尝试了Microsoft.Extensions.Identity.Core版本7.0.0,它导致了一些错误。我不得不切换到6.0.0版本,它得到了解决。

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
  </ItemGroup>
</PropertyGroup>

相关问题