代码之家  ›  专栏  ›  技术社区  ›  Johannes Riecken

azure storage unity uwp应用程序的namesolutionfailure(在播放器中工作)

  •  0
  • Johannes Riecken  · 技术社区  · 6 年前

    我有一个HoloLens应用程序,应该从azure存储加载数据。当使用 WindowsAzure.Storage package converted to a unitypackage ,我可以在使用unity player时加载数据,在使用普通的2dxaml uwp应用程序进行测试时,也可以在hololens上使用该api加载数据,但是,在调试il2cpp项目时,我得到一个“webexception:error:namesolutionfailure”( full log )

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

    • 打开Unity 2018.2(我使用2018.2.14f,2018.2是必要的 https,这显然是连接到azure所必需的)
    • 将unity project的.net版本设置为4.x,因为azure存储api使用await/async,所以我使用il2cpp作为后端。.NET后端提供了一些未找到的newtonsoft.json函数的错误,这可能是导致我出现问题的原因?assets/plugins/newtonsoft.json.dll存在并引用.net v4.0.30319。

    错误:方法 System.Threading.Tasks.Task 一 newtonsoft.json.linq.jobject::loadAsync(newtonsoft.json.jsonReader,system.threading.cancellationToken)` 目标框架中不存在。引用自 位于system.void的Microsoft.Windowsazure.storage.dll microsoft.windowsazure.storage.odataerrorhelper/d\uu 2::移动下一步()。

    • 在(0,0,2)处创建名为imagegrid的空游戏对象
    • 将下面的脚本populateImageGrid.cs导入项目并将其附加到ImageGrid
    • 从1*1*0.1立方体创建一个预设,并将图像网格游戏对象的公共场图像网格平铺设置为该预设
    • 删除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);
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Johannes Riecken    6 年前

    诀窍是等到30秒超时后,出现namesolutionfailure的错误消息,这使我明白应该在appxmanifest中激活internet权限。