【问题标题】:NameResolutionFailure with Azure Storage Unity UWP app (works in Player)NameResolutionFailure 与 Azure Storage Unity UWP 应用程序(在播放器中工作)
【发布时间】:2019-04-02 14:26:05
【问题描述】:

我有一个 Hololens 应用程序,它应该从 Azure 存储加载数据。使用WindowsAzure.Storage package converted to a unitypackage 时,我可以在使用 Unity Player 时加载数据,并且在使用普通 2D XAML UWP 应用程序进行测试时,我还可以在 Hololens 上使用该 API 加载数据,但是,在调试 IL2CPP 项目时,我得到一个“WebException:错误:NameResolutionFailure”(full log)。

以下是构建简化测试项目的步骤:

  • 打开Unity 2018.2(我用的是2018.2.14f,需要2018.2才能使用 https,这显然是连接到 Azure 所必需的)
  • 将 Unity Project 的 .NET 版本设置为 4.x,因为 Azure Storage API 使用 await/async,我使用 IL2CPP 作为后端。 .NET 后端给出了一些关于未找到 Newtonsoft.JSON 函数的错误,这可能是导致我出现问题的原因? Assets/Plugins/Newtonsoft.Json.dll 存在并引用 .NET v4.0.30319。

错误:方法 System.Threading.Tasks.Task1 Newtonsoft.Json.Linq.JObject::LoadAsync(Newtonsoft.Json.JsonReader,System.Threading.CancellationToken)` 目标框架中不存在。它引用自 System.Void 中的 Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage.ODataErrorHelper/d__2::MoveNext()。

  • 在 (0, 0, 2) 处创建一个名为 ImageGrid 的空游戏对象
  • 将下面的脚本 PopulateImageGrid.cs 导入到项目中,并附加到 ImageGrid 中
  • 从 1*1*0.1 立方体创建一个预制件,并将 Image Grid 游戏对象的公共字段 Image Grid Tile 设置为该预制件
  • 删除 Assets/Plugins/Microsoft.CSharp.dll,因为 Unity 抱怨它存在两次
  • 构建为 UWP,在 Visual Studio 中加载构建的项目,然后选择 Release 和 x86(或部署到 Hololens)开始

这是 PopulateImageGrid.cs。随意连接代码中提供的帐户详细信息,因为它是没有敏感数据的免费帐户。

using System.Collections;
using System.Collections.Generic;
// using UnityEditor.PackageManager;
using UnityEngine;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.File;
using System;

public class PopulateImageGrid : MonoBehaviour {

    public Transform ImageGridTile;

    async void Start()
    {
        Debug.Log("In PopulateImageGrid.Start()");
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(@"DefaultEndpointsProtocol=https;FileEndpoint=https://meshiconstorage.file.core.windows.net;AccountName=meshiconstorage;AccountKey=2Myeg/WUowehkrAY8Lgl361xxylfkMdITrVapKKVPyo9bVFqN6/uD1S66CB4oTPnnWncLubiVjioBUIT+4utaw==");
        CloudFileClient cloudFileClient = storageAccount.CreateCloudFileClient();
        string shareName = "meshicon-share1";
        var cloudFileShare = cloudFileClient.GetShareReference(shareName);
        CloudFileDirectory rootDirectory = cloudFileShare.GetRootDirectoryReference();
        var fileDirectory = rootDirectory.GetDirectoryReference("images");

        FileContinuationToken token = null;

        int row = 0;
        int col = 0;
        const int width = 32;
        const int height = 32;
        do
        {
            FileResultSegment frs = await fileDirectory.ListFilesAndDirectoriesSegmentedAsync(token);
            foreach (var result in frs.Results)
            {
                Debug.Log("In loop with " + result.ToString());
                Vector3 position = new Vector3(col++ * 0.13f - 0.39f, row * 0.13f - 0.26f, 0f);
                Quaternion rotation = Quaternion.identity;
                Transform gridTile = Instantiate(ImageGridTile);
                gridTile.transform.parent = gameObject.transform;
                gridTile.localPosition = position;
                gridTile.localRotation = rotation;
                if (col > 6)
                {
                    row++;
                    col = 0;
                }
                byte[] imgData = new byte[10000];
                int size = await ((CloudFile)result).DownloadToByteArrayAsync(imgData, 0);
                Debug.Log("Downloaded to byte[]");
                Texture2D texture = new Texture2D(width, height);
                byte[] realImgData = new byte[size];
                Array.Copy(imgData, realImgData, size);
                texture.LoadImage(imgData);
                gridTile.GetComponent<MeshRenderer>().material.mainTexture = texture;
            }
        } while (token != null);
    }
}

【问题讨论】:

    标签: c# azure unity3d uwp azure-storage


    【解决方案1】:

    诀窍是等到 30 秒超时后出现 NameResolutionFailure 的错误消息,这让我很明显应该在 appxmanifest 中激活互联网权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2017-10-06
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多