在 Xamarin 应用程序中实例化 CloudStorageAccount 会导致未处理的异常

Posted

技术标签:

【中文标题】在 Xamarin 应用程序中实例化 CloudStorageAccount 会导致未处理的异常【英文标题】:Instantiating CloudStorageAccount in Xamarin application causes unhandled exception 【发布时间】:2017-10-07 22:08:52 【问题描述】:

在this 文章之后,我创建了一个空白 Xamarin 表单应用程序,将 WindowsStorage.Azure 包添加到 PCL 和 android 应用程序(我现在删除了 ios 和 UWP,因为它只是一个测试应用程序)

  <package id="WindowsAzure.Storage" version="8.1.1" targetFramework="portable45-net45+win8+wp8+wpa81" />

并尝试与库进行交互,但只要我做任何事情,应用程序就会崩溃并出现未处理的异常:

无论我做什么,创建一个新的 StorageCredentials 对象:

var creds = new StorageCredentials("something", "other");

或新的 CloudStorageAccount:

var storageAccount = CloudStorageAccount.Parse(storageConnectionString);

我也一样。 我已经阅读了github documentation 并看不出这是什么原因。

有没有人遇到过这个问题,可以帮忙看看这里出了什么问题?

编辑

我可以从 debu 窗口看到它抛出了 NotImplementedException:

05-09 14:45:16.452 D/Mono    ( 3772): DllImport attempting to load: '/system/lib/liblog.so'.
05-09 14:45:16.476 D/Mono    ( 3772): DllImport loaded library '/system/lib/liblog.so'.
05-09 14:45:16.476 D/Mono    ( 3772): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
05-09 14:45:16.476 D/Mono    ( 3772): Searching for '__android_log_print'.
05-09 14:45:16.476 D/Mono    ( 3772): Probing '__android_log_print'.
05-09 14:45:16.476 D/Mono    ( 3772): Found as '__android_log_print'.
05-09 14:45:16.480 I/MonoDroid( 3772): UNHANDLED EXCEPTION:
05-09 14:45:16.485 I/MonoDroid( 3772): System.AggregateException: One or more errors occurred. ---> System.NotImplementedException: The method or operation is not implemented.
05-09 14:45:16.485 I/MonoDroid( 3772):   at Microsoft.WindowsAzure.Storage.Auth.StorageCredentials..ctor (System.String accountName, System.String keyValue, System.String keyName) [0x00006] in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\AspNet\Microsoft.WindowsAzure.Storage.Facade\FacadeLib\Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.cs:77 
05-09 14:45:16.485 I/MonoDroid( 3772):   at Microsoft.WindowsAzure.Storage.Auth.StorageCredentials..ctor (System.String accountName, System.String keyValue) [0x00000] in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\AspNet\Microsoft.WindowsAzure.Storage.Facade\FacadeLib\Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.cs:71 
05-09 14:45:16.485 I/MonoDroid( 3772):   at TestApp.Droid.MainPage+<StartPolling>d__3.MoveNext () [0x0001d] in D:\XamarinAzureStorageTest\TestApp.Droid\TestApp.Droid\MainPage.xaml.cs:27 
05-09 14:45:16.485 I/MonoDroid( 3772):    --- End of inner exception stack trace ---
05-09 14:45:16.485 I/MonoDroid( 3772):   at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00014] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2157 
05-09 14:45:16.485 I/MonoDroid( 3772):   at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00052] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:3189 
05-09 14:45:16.485 I/MonoDroid( 3772):   at System.Threading.Tasks.Task.Wait () [0x00000] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:3054 
05-09 14:45:16.485 I/MonoDroid( 3772):   at TestApp.Droid.MainPage.StartPolling_Clicked (System.Object sender, System.EventArgs e) [0x0004e] in D:\XamarinAzureStorageTest\TestApp.Droid\TestApp.Droid\MainPage.xaml.cs:55 
05-09 14:45:16.485 I/MonoDroid( 3772):   at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x00020] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\Button.cs:125 
05-09 14:45:16.485 I/MonoDroid( 3772):   at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer+ButtonClickListener.OnClick (Android.Views.View v) [0x0000b] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:298 
05-09 14:45:16.485 I/MonoDroid( 3772):   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00011] in /Users/builder/data/lanes/4468/b16fb820/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1806 
05-09 14:45:16.485 I/MonoDroid( 3772):   at (wrapper dynamic-method) System.Object:0f149978-de2e-4679-a635-699ceeddec42 (intptr,intptr,intptr)
05-09 14:45:16.485 I/MonoDroid( 3772): ---> (Inner Exception #0) System.NotImplementedException: The method or operation is not implemented.
05-09 14:45:16.485 I/MonoDroid( 3772):   at Microsoft.WindowsAzure.Storage.Auth.StorageCredentials..ctor (System.String accountName, System.String keyValue, System.String keyName) [0x00006] in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\AspNet\Microsoft.WindowsAzure.Storage.Facade\FacadeLib\Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.cs:77 
05-09 14:45:16.485 I/MonoDroid( 3772):   at Microsoft.WindowsAzure.Storage.Auth.StorageCredentials..ctor (System.String accountName, System.String keyValue) [0x00000] in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\AspNet\Microsoft.WindowsAzure.Storage.Facade\FacadeLib\Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.cs:71 
05-09 14:45:16.485 I/MonoDroid( 3772):   at TestApp.Droid.MainPage+<StartPolling>d__3.MoveNext () [0x0001d] in D:\XamarinAzureStorageTest\TestApp.Droid\TestApp.Droid\MainPage.xaml.cs:27 <---
05-09 14:45:16.500 W/art     ( 3772): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
05-09 14:45:16.604 D/Mono    ( 3772): DllImport searching in: '__Internal' ('(null)').
05-09 14:45:16.604 D/Mono    ( 3772): Searching for 'java_interop_jnienv_throw'.
05-09 14:45:16.604 D/Mono    ( 3772): Probing 'java_interop_jnienv_throw'.
05-09 14:45:16.604 D/Mono    ( 3772): Found as 'java_interop_jnienv_throw'.
Thread finished: <Thread Pool> #4
The thread 'Unknown' (0x4) has exited with code 0 (0x0).
Thread finished: <Thread Pool> #5
05-09 14:45:57.900 D/Mono    ( 3772): [0x9b2de930] worker finishingThe thread 'Unknown' (0x5) has exited with code 0 (0x0).

【问题讨论】:

尝试查看调试/输出窗口以获取有关错误的更多信息。有时您确实需要点击“继续”才能显示。但在一个疯狂的猜测(没有任何进一步的信息),除了 pcl 之外,您是否将 azure 存储包添加到您正在启动的本机。 【参考方案1】:

...为您解决方案中的所有项目安装最新的稳定版本...

回复:步骤 3 https://docs.microsoft.com/en-us/azure/storage/storage-xamarin-blob-storage

Azure 存储使用本机功能/特性,因此您不仅需要在 PCL 项目中安装包,还需要在每个本机应用程序项目中安装包。

【讨论】:

以上是关于在 Xamarin 应用程序中实例化 CloudStorageAccount 会导致未处理的异常的主要内容,如果未能解决你的问题,请参考以下文章

Xamarin 表单 - 导航后 CustomRenderer 不工作

VS/Xamarin Android开发Follow Me

Xamarin.Forms Shell 如何在路由导航中向字符串注入多个不同的值

xamarin Android Timer

Android 上的 Xamarin WebView 显示多个实例

C# CodeDom System.TypeLoadException XamMac2 Xamarin macOS