0

I am new azure mobile service and ASP.NET MVC and have successfully created a mobile service and published it. It works fine.

My issue is how do I consume it in ASP.NET MVC application?

I created an ASP.NET MVC application from scratch, added the following nuget WindowsAzure.MobileService.

Happy days no issues.

In my controller I have

public static MobileServiceClient MobileService = new MobileServiceClient("http://localhost:50270/");

var list = await MobileService.InvokeApiAsync<IEnumerable<xxxx>>("xxxxxx",System.Net.Http.HttpMethod.Get, null);

When I run the website, it breaks with the following error. For some reason it does not like the @Html (Razor syntax)

Compiler Error Message: CS0012: The type 'System.Object' is defined in an   assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Source Error:


Line 18:                     <span class="icon-bar"></span>
Line 19:                 </button>
Line 20:--->Error        @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
Line 21:             </div>
Line 22:             <div class="navbar-collapse collapse">

If I get rid of "WindowsAzure.MobileService" package it works fine.

What am I doing wrong here? Am I missing something?

Also is this the right way to consume Mobile Service in ASP.NET?

mason
  • 31,774
  • 10
  • 77
  • 121
Vishal Patel
  • 130
  • 1
  • 2
  • 10

1 Answers1

2

This is an issue with using Portable Class Libraries in an MVC application. You can add the System.Runtime assembly to your web.config (or the web.config for the views folder) to fix this problem.

<compilation debug="true" targetFramework="4.5">
    <assemblies>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies>
</compilation>

From this question with a similar issue: Portable Class Library in MVC 4 / Razor with Visual Studio 2012 RC?

Community
  • 1
  • 1
Matt Milner
  • 825
  • 5
  • 6