4

Hello I have a silverlight project for WP8.1 that is a game. I use a backgroundTask to alert the user about when he last played, if he is too slow to comply I would like to make a call to the server from the bagroundTask to resign from the games.

The backgroundTask is made using stackoverflow and this blog, just basic implementations of the backgroundTask.

I then install the NuGet Package Microsoft.Azure.Mobile.Client and everything is fine, I then do a compile, everything succeeds.

The app installs and splashscreen appears, then I get an error in the main project at the initialization of MobileServiceClient in App.xaml.cs

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

The exception in the above line states:

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.

The only change was the install of the NuGet package in the backgroundTask project. The stack trace output for the exception above.

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()

I have not been able to solve this issue.

Extra

I am able to do normal http calls to the web by using the proposed code, replicated here:

BackgroundTaskDeferral _deferral;

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

Update based on Adrian Halls Answer

The code works, my front application can communicate with the server and everything. The backgroundTask, can extract information from the device everything is fine, everything compiles and runs.

I then add the NuGet package to the backgroundTask and suddenly the above error appears, when I deploy this solution to the client.

I am running VS2015, Win10, and have v2.0.1 installed of Microsoft.Azure.Mobile.Client. I have seen some odd behaviours with silverlight projects on win10 before.

Community
  • 1
  • 1
JTIM
  • 2,774
  • 1
  • 34
  • 74

1 Answers1

2

The error indicates a problem with your .NET setup - the error is in mscorlib (the basic library for .NET). Try to add a reference to the specific library that you need. Also, ensure that you have installed v2.0.1 (or later) or the Microsoft.Azure.Mobile.Client library.

Adrian Hall
  • 7,990
  • 1
  • 18
  • 26
  • It is the version that is installed, I will try and amend this. So the install of the package in one project will influence the dependencies in another? Just to clarify? – JTIM May 23 '16 at 20:33
  • I am a bit unsure now that I read your answer again. The code works, my front application can communicate with the server and everything. The backgroundTask, can extract information from the device everything is fine, everything compiles and runs. I then add the NuGet package to the backgroundTask and suddenly the above error appears. I am running VS2015, Win10, and have v2.0.1 installed of Microsoft.Azure.Mobile.Client. – JTIM May 24 '16 at 16:39
  • @JTIM I thought that background tasks always have to be WPA, not silverlight? Can you try putting it in a separate assembly and changing the target to non-Silverlight? – lindydonna May 24 '16 at 21:00
  • @lindydonna-msft I am sorry I will try to be more clear. The backgroundTask is a WindowsPhone8.1 project (not silverlight). The main project is a silverlight project. Both working fine. Adding the nuget package to backgroundTask (non silverlight project), influences the main app (silverlight project) with the error specified. – JTIM May 25 '16 at 10:06
  • @lindydonna-msft did any of you have any experience with this? – JTIM Jun 08 '16 at 09:29