![](/img/trans.png)
[英]The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
[英]The type initializer for 'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an exception error in Xamarin.forms
我正在研究Xamarin提供的AzureStorage雲解決方案。 https://developer.xamarin.com/guides/xamarin-forms/cloud-services/storage/azure-storage/
這就是我在GetContainer()方法中得到的。
“Microsoft.WindowsAzure.Storage.CloudStorageAccount”的類型初始值設定項引發異常
我在示例項目中應用了我的連接字符串並且它有效,但不在我自己的項目中。
有沒有人遇到過這個問題? 請幫我。
提前致謝。
錯誤信息 :
System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
at Microsoft.WindowsAzure.Storage.CloudStorageAccount.Setting (System.String name, System.String[] validValues) [0x00000] in <667a5fa37f124e50ab7a68ecb3437b13>:0
at Microsoft.WindowsAzure.Storage.CloudStorageAccount..cctor () [0x00000] in <667a5fa37f124e50ab7a68ecb3437b13>:0
--- End of inner exception stack trace ---
at MyTenantWorld.AzureStorage.GetContainer (MyTenantWorld.ContainerType containerType) [0x00020] in <9816076ee17d42efaf1050c5169a4310>:0
at MyTenantWorld.AzureStorage+<UploadFileAsync>d__3.MoveNext () [0x0001a] in <9816076ee17d42efaf1050c5169a4310>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at MyTenantWorld.SettingsPage+<SaveData>d__20.MoveNext () [0x00309] in <9816076ee17d42efaf1050c5169a4310>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at at (wrapper dynamic-method) System.Object:a4fed05a-cd7a-4756-85bb-5dd975374042 (intptr,intptr)
由於AzureStorage.cs下定義的GetContainer
方法如下:
static CloudBlobContainer GetContainer(ContainerType containerType)
{
var account = CloudStorageAccount.Parse(Constants.StorageConnection);
var client = account.CreateCloudBlobClient();
return client.GetContainerReference(containerType.ToString().ToLower());
}
似乎CloudStorageAccount.Parse
引發了錯誤,但是從BergQuester關於CloudStorageAccount.Parse的鏈接中,我們發現此錯誤不是來自可預測的異常。
從堆棧跟蹤中,我們可以在CloudStorageAccount.cs中找到Setting(string name, params string[] validValues)
時發生的錯誤。 我使用了WindowsAzure.Storage 8.3.0並在我的BruceChen_Mobile.UWP項目和PCL項目下進行了測試,它可以按照我的azure存儲連接字符串工作。
我在示例項目中應用了我的連接字符串並且它有效,但不在我自己的項目中。
我建議你檢查你的應用程序和xamarin-forms-samples之間的包。 或者您可以為我們提供可重現的示例項目以縮小此問題。
我通過從我的本機項目(不僅僅是在PCL項目中)添加對WindowsAzure.Storage nuget包的引用來修復此問題,因為它需要在這些引用中定義的一些本機實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.