1
votes

I'm working on AzureStorage cloud solution provided by Xamarin. https://developer.xamarin.com/guides/xamarin-forms/cloud-services/storage/azure-storage/

And this is what I got in GetContainer() method.

The type initializer for 'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an exception

I applied my connection string in the sample project and it worked, but not in my own project.

Has anyone ever faced this issue? Please help me.

Thanks in advance.

Error message :

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)
2
Without knowing what the exception is, it's hard to know what's going on. Can you add the full crash info? e.g. Click the copy button in the crash window that xamarin gives you and paste here. For what it's worth, the documentation for the constructor you're using lists the possible exceptions that it can throw.BergQuester
@BergQuester, I just added the error message, thanks.MrIndomitable
System.NotImplementedException, seems a method here isn't implemented in the Mono framework (which is used for Xamarin) or the version of the library you've linked against.Lasse V. Karlsen
@LasseV.Karlsen, can you please clarify it?MrIndomitable

2 Answers

2
votes

As the GetContainer method defined under AzureStorage.cs as follows:

static CloudBlobContainer GetContainer(ContainerType containerType)
{
     var account = CloudStorageAccount.Parse(Constants.StorageConnection);
     var client = account.CreateCloudBlobClient();
     return client.GetContainerReference(containerType.ToString().ToLower());
}

It seems that the error was thrown by CloudStorageAccount.Parse, but from BergQuester's link about CloudStorageAccount.Parse, we could find that this error is not from the predictable exceptions.

From your stack trace, we could find the error was thrown at Setting(string name, params string[] validValues) from CloudStorageAccount.cs. I used WindowsAzure.Storage 8.3.0 and tested it under my BruceChen_Mobile.UWP project and PCL project, it could work as expected with my azure storage connection string.

I applied my connection string in the sample project and it worked, but not in my own project.

I would recommend you checking the packages between your application and the xamarin-forms-samples. Or you could provide a reproducible sample project for us to narrow this issue.

1
votes

I fixed this issue on mine by adding a reference to the WindowsAzure.Storage nuget package from my native projects (not just in the PCL project), as it requires some native implementations that are defined in these references.