我使用的是Unity 2019.3.6f1。我创建了一个简单的 DLL,用于连接到 Azure 并上传文件。但是,当我调用此 DLL 来尝试连接到 Azure blob 存储时,我得到以下堆栈跟踪:
NotImplementedException:该方法或操作未实现。
System.Net.Http.HttpClientHandler.get_MaxConnectionsPerServer ()(位于
:0)
Azure.Core.Pipeline.ServicePointHelpers.SetLimits
(System.Net.Http.HttpMessageHandler 消息处理程序)(位于
:0)
Azure.Core.Pipeline.HttpClientTransport.CreateDefaultClient ()(位于
:0)
Azure.Core.Pipeline.HttpClientTransport..ctor ()(位于
:0)
Azure.Core.Pipeline.HttpClientTransport..cctor ()(位于
:0) 重新抛出为
TypeInitializationException:类型初始值设定项
“Azure.Core.Pipeline.HttpClientTransport”引发异常。
Azure.Core.ClientOptions..ctor ()(位于
:0)
Azure.Storage.Blobs.BlobClientOptions..ctor
(Azure.Storage.Blobs.BlobClientOptions+ServiceVersion 版本)(位于
:0)
Azure.Storage.Blobs.BlobServiceClient..ctor(System.String
连接字符串、Azure.Storage.Blobs.BlobClientOptions 选项)(位于
:0)
Azure.Storage.Blobs.BlobServiceClient..ctor(System.String
连接字符串)(位于:0)
Cineon.UnityToAzureConnection+d__1.MoveNext ()(位于
:0)
--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()(位于
:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+c.b__6_0
(System.Object 状态)(位于 :0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (位于
:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()
这是我的DLL代码(符合这个 Microsoft 快速入门指南 https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet):
public class UnityToAzureConnection
{
private readonly static string m_connectionString = "CENSORED";
public static async void CreateConnection(string _path, string _fileName)
{
BlobServiceClient blobServiceClient = new BlobServiceClient(m_connectionString);
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync("imagetest");
BlobClient blobClient = containerClient.GetBlobClient(_fileName);
using (FileStream _fs = File.Open(Path.Combine(_path, _fileName), FileMode.Open))
{
await blobClient.UploadAsync(_fs, true);
}
}
}
我只需调用此 DLL 的 CreateConnection 方法并传入我的“Application.dataPath”和文件名。但是,我随后得到了上述异常。
我已将所有其他所需的 DLL 从项目构建文件夹中提取到插件文件夹中,所以我不确定为什么会发生这种情况。
任何帮助将不胜感激。
请注意,我刚刚开始走出我的舒适区,所以我希望我的帖子符合 StackOverflow 的问题标准。
[P.S.] 显然“CENSORED”不是我的实际连接字符串,只是隐藏敏感信息。
更新 29/05/2021我已经确认我的连接代码在简单的 .net 控制台应用程序中使用时确实有效(但是,我确实必须将容器名称调整为全部小写)。此错误仅发生在 Unity 中。再次强调,任何和所有的帮助将不胜感激。