.NET 项目中 System.Runtime 版本 6.0.0.0 的 FileLoadException

问题描述 投票:0回答:1

运行 .NET 应用程序时,我遇到

FileLoadException
,特别是与加载
System.Runtime
程序集版本 6.0.0.0 相关。完整的错误信息如下:

Could not load assembly l'assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

在我的应用程序中,我有 Azure blob 方法来上传一些附件。 所有 Azure blob nuget 都是最新的。

环境:

  • 目标.NET运行时版本:.NETframework 4.6.2
  • 开发环境:Visual Studio 2022
  • 操作系统:Windows 11

我找到了数百条建议,但没有一个对我有帮助。

我在app.config中手动添加了程序集

<dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> </dependentAssembly>
,没有结果。

c# .net azure-blob-storage .net-assembly
1个回答
0
投票

我使用 .NET Framework 4.6.2 创建了一个控制台应用程序,遵循 MSDOC 并使用下面的代码在 Azure 存储中创建 Blob 并上传文件。

var blobServiceClient = new BlobServiceClient(
      new Uri("https://kpstorage0103.blob.core.windows.net"),
      new DefaultAzureCredential());

string containerName = "myblob-" + Guid.NewGuid().ToString();

BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);

string localPath = "data";
Directory.CreateDirectory(localPath);
string fileName = "file-" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);

await Task.Run(() => File.WriteAllText(localFilePath, "Hello, World!"));

BlobClient blobClient = containerClient.GetBlobClient(fileName);

Console.WriteLine("Uploading to Blob storage as blob:\n\t {0}\n", blobClient.Uri);
await blobClient.UploadAsync(localFilePath, true);

Console.WriteLine("Done");
Thread.Sleep(1000);
  • 在存储帐户中为我的帐户分配了 Storage Blob Data Contributor 角色
  • 已安装
    Azure.Storage.Blobs
    NuGet 包,版本为
    12.9.11

.csproj:

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Security.Cryptography.ProtectedData" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

传送门:

  • Blob 已创建:

enter image description here

  • 已上传文件:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.