【问题标题】:WP Silverlight BackgroundTask Communication with AzureWP Silverlight BackgroundTask 与 Azure 的通信
【发布时间】:2016-05-22 08:13:27
【问题描述】:

您好,我有一个针对 WP8.1 的 silverlight 项目,它是一个游戏。我使用 backgroundTask 来提醒用户他上次玩的时间,如果他太慢而无法遵守,我想从 bagroundTask 调用服务器以退出游戏。

backgroundTask 是使用stackoverflowthis blog 制作的,只是backgroundTask 的基本实现。

然后我安装 NuGet 包Microsoft.Azure.Mobile.Client 一切正常,然后我进行编译,一切成功。

应用程序安装并出现启动画面,然后我在App.xaml.cs中的MobileServiceClient初始化时在主项目中出现错误

 public MobileServiceClient MobileService = new MobileServiceClient(
        "https://xxxxx.azurewebsites.net"
    );

上述行中的异常状态:

“System.IO.FileNotFoundException”类型的异常发生在 mscorlib.ni.dll 中,但未在用户代码中处理 附加信息:无法加载文件或程序集“System.Runtime.InteropServices,Version=4.0.10.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。

唯一的变化是在 backgroundTask 项目中安装了 NuGet 包。上述异常的堆栈跟踪输出。

在 System.ModuleHandle.ResolveType(RuntimeModule 模块,Int32 typeToken,IntPtr* typeInstArgs,Int32 typeInstCount,IntPtr* methodInstArgs,Int32 methodInstCount,ObjectHandleOnStack 类型) 在 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule 模块,Int32 typeToken,RuntimeTypeHandle[] typeInstantiationContext,RuntimeTypeHandle[] methodInstantiationContext) 在 System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,Type[] genericTypeArguments,Type[] genericMethodArguments) 在 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport 范围,Assembly& lastAptcaOkAssembly,RuntimeModule 装饰模块,MetadataToken 装饰令牌,RuntimeType attributeFilterType,Boolean mustBeInheritable,Object[] 属性,IListderivedAttributes,RuntimeType&attributeType,IRuntimeMethodInfo&ctor,Boolean&ctorHasParameters,Boolean&isVar 在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule 装饰模块,Int32 装饰元数据令牌,Int32 pcaCount,RuntimeType attributeFilterType,布尔 mustBeInheritable,IList 派生属性,布尔 isDecoratedTargetSecurityTransparent) 在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule 装饰模块,Int32 装饰元数据令牌,Int32 pcaCount,RuntimeType attributeFilterType,布尔 isDecoratedTargetSecurityTransparent) 在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly 程序集,RuntimeType caType) 在 System.Reflection.RuntimeAssembly.GetCustomAttributes(类型属性类型,布尔继承) 在 System.Attribute.GetCustomAttributes(程序集元素,类型属性类型,布尔继承) 在 Microsoft.WindowsAzure.MobileServices.PlatformInformationExtensions.GetVersionFromAssemblyFileVersion(IPlatformInformation 平台信息) 在 Microsoft.WindowsAzure.MobileServices.PlatformInformation.get_Version() 在 Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.GetUserAgentHeader() 在 Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient..ctor(IEnumerable`1 处理程序,Uri applicationUri,String installationId) 在 Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor(Uri mobileAppUri,HttpMessageHandler[] 处理程序) 在 Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor(字符串 mobileAppUri,HttpMessageHandler[] 处理程序) 在 BC_Menu.App..ctor()

我没能解决这个问题。

额外

我可以使用 proposed code 对网络进行正常的 http 调用,在此处复制:

BackgroundTaskDeferral _deferral;

public async void Run(IBackgroundTaskInstance taskInstance)
{
    _deferral = taskInstance.GetDeferral();
    // your async code
    _deferral.Complete();
}

根据 Adrian Halls 答案更新

代码有效,我的前端应用程序可以与服务器和一切通信。 backgroundTask,可以从设备中提取信息一切都很好,一切都编译并运行。

然后我将 NuGet 包添加到 backgroundTask,当我将此解决方案部署到客户端时,突然出现上述错误。

我正在运行 VS2015、Win10,并安装了 Microsoft.Azure.Mobile.Client v2.0.1。我在 win10 before 上看到了 Silverlight 项目的一些奇怪行为。

【问题讨论】:

    标签: azure silverlight windows-phone-8 windows-phone-8.1 azure-mobile-services


    【解决方案1】:

    该错误表明您的 .NET 设置存在问题 - 错误位于 mscorlib(.NET 的基本库)中。尝试添加对您需要的特定库的引用。此外,请确保您已安装 v2.0.1(或更高版本)或 Microsoft.Azure.Mobile.Client 库。

    【讨论】:

    • 是安装的版本,我会尝试修改这个。那么在一个项目中安装包会影响另一个项目中的依赖关系吗?只是为了澄清?
    • 再次阅读您的答案后,我有点不确定。代码有效,我的前端应用程序可以与服务器和一切通信。 backgroundTask,可以从设备中提取信息一切都很好,一切都编译并运行。然后我将 NuGet 包添加到 backgroundTask 中,突然出现上述错误。我正在运行 VS2015、Win10,并安装了 Microsoft.Azure.Mobile.Client 的 v2.0.1。
    • @JTIM 我认为后台任务总是必须是 WPA,而不是 silverlight?您可以尝试将其放在单独的程序集中并将目标更改为非 Silverlight 吗?
    • @lindydonna-msft 很抱歉,我会尽量说得更清楚。 backgroundTask 是一个WindowsPhone8.1 项目(不是silverlight)。主要项目是silverlight项目。两者都工作正常。将nuget包添加到backgroundTask(非silverlight项目),会影响主应用程序(silverlight项目)并指定错误。
    • @lindydonna-msft 你们有没有这方面的经验?
    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多