您好,我有一个适用于 WP8.1 的 silverlight 项目,它是一款游戏。我使用后台任务来提醒用户他上次玩游戏的时间,如果他太慢而无法遵守,我想从 bagroundTask 调用服务器以退出游戏。
backgroundTask是使用stackoverflow制作的和 this blog ,只是backgroundTask的基本实现。
然后我安装 NuGet 包 Microsoft.Azure.Mobile.Client
一切都很好,然后我进行编译,一切都成功了。
应用程序安装并出现启动画面,然后我在初始化 MobileServiceClient
时在主项目中收到错误在App.xaml.cs
public MobileServiceClient MobileService = new MobileServiceClient(
"https://xxxxx.azurewebsites.net"
);
以上行中的异常状态:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code Additional information: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
唯一的变化是在backgroundTask 项目中安装NuGet 包。上述异常的堆栈跟踪输出。
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at Microsoft.WindowsAzure.MobileServices.PlatformInformationExtensions.GetVersionFromAssemblyFileVersion(IPlatformInformation platformInformation) at Microsoft.WindowsAzure.MobileServices.PlatformInformation.get_Version() at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.GetUserAgentHeader() at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient..ctor(IEnumerable`1 handlers, Uri applicationUri, String installationId) at Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor(Uri mobileAppUri, HttpMessageHandler[] handlers) at Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor(String mobileAppUri, HttpMessageHandler[] handlers) at 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 的回答进行更新
代码有效,我的前端应用程序可以与服务器和所有内容进行通信。后台任务,可以从设备中提取信息,一切都很好,一切都编译并运行。
然后,我将 NuGet 包添加到 backgroundTask 中,当我将此解决方案部署到客户端时,突然出现上述错误。
我运行的是 VS2015、Win10,并安装了 v2.0.1 Microsoft.Azure.Mobile.Client。我在win10 before上看到了silverlight项目的一些奇怪行为.
最佳答案
该错误表明您的 .NET 设置存在问题 - 错误位于 mscorlib(.NET 的基本库)中。尝试添加对您需要的特定库的引用。另外,请确保您已安装 v2.0.1(或更高版本)或 Microsoft.Azure.Mobile.Client 库。
关于azure - WP Silverlight 后台任务与 Azure 的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37372006/