【问题标题】:Azure function v2, Core 3.1 Could not load file or assembly System.Memory, Version=4.2.0.0Azure 函数 v2,Core 3.1 无法加载文件或程序集 System.Memory,版本 = 4.2.0.0
【发布时间】:2020-02-03 14:07:50
【问题描述】:

我在 Core 3.1 上本地运行 Azure 函数 v2。函数连接从 EventHub 读取事件并将数据写入 Redis 数据库。 连接函数出错时

System.Private.CoreLib: Exception while executing function: 
 One or more errors occurred. (Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.). 
 Pipelines.Sockets.Unofficial: Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

相同的 Redis 连接代码在 Azure 函数之外正常工作。

我已将 System.Memory nuget 包 v 4.5.3 安装到项目中,但它没有帮助。 Core 3.1 的 nuget 中没有列出 System.Memory 4.2 版

函数使用启动

[assembly: FunctionsStartup(typeof(...))]

项目文件

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
    <PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
    <PackageReference Include="System.Memory" Version="4.5.3" />
    <PackageReference Include="Utf8Json" Version="1.3.7" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Configuration\Configuration.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

怎么了?

【问题讨论】:

    标签: azure .net-core serverless


    【解决方案1】:

    通过在项目 .csproj 文件中将 Azure 函数版本更改为 v3 解决了该问题。

      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <AzureFunctionsVersion>v3</AzureFunctionsVersion>
      </PropertyGroup>
    

    【讨论】:

      【解决方案2】:

      如果问题仍然存在,请验证您使用的是正确版本的 Azure Functions Core Tools (v3),我碰巧从 nodejs 中获取了版本 2,即我在 nodejs 中安装了版本 2,在中安装了版本 3路径中的来自microsoft的文件夹它们都是但我拿了第一个是nodejs的文件夹,它一直给我错误,直到我删除nodejs一个,你可以在nodejs中将它更新到版本3,我想它会工作一样的。

      【讨论】:

        【解决方案3】:

        您能否尝试在您的 .csproj 文件中添加 true:

         <PropertyGroup>
            ...
            <UseNETCoreGenerator>true</UseNETCoreGenerator>
          </PropertyGroup>
        

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-23
        相关资源
        最近更新 更多