我有一个Hololens应用程序,应从Azure存储加载数据。使用WindowsAzure.Storage package converted to a unitypackage时,我可以在使用Unity Player时加载数据,并在使用普通的2D XAML UWP应用进行测试时,也可以在Hololens上使用该API加载数据,但是,在调试IL2CPP项目时,我得到一个“ WebException:错误:NameResolutionFailure”(full log)。
以下是构建简化的测试项目的步骤:
错误:方法
System.Threading.Tasks.Task
1 Newtonsoft.Json.Linq.JObject :: LoadAsync(Newtonsoft.Json.JsonReader,System.Threading.CancellationToken)` 在目标框架中不存在。引用自 System.Void上的Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage.ODataErrorHelper / d__2 :: MoveNext()。
这是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);
}
}
答案 0 :(得分:0)
诀窍是要等到30秒超时后,出现NameResolutionFailure的错误消息,这使我很明显我应该在appxmanifest中激活Internet权限。