2

I'm trying to use Asp.NET WebAPI module but I get a weird error. When I try to run this simple program:

class Program
{
    static void Main(string[] args)
    {
        System.Net.Http.HttpClient client = new HttpClient();
        string data = client.GetStringAsync("http://www.kralizek.se/").Result;

        Console.WriteLine(data);

        Console.ReadLine();
    }
}

I have this error.

System.MissingMethodException was unhandled
  Message=Method not found: 'System.Threading.Tasks.Task`1<System.String> System.Net.Http.HttpClient.GetStringAsync(System.String)'.
  Source=Connector.App
  StackTrace:
       at ConnectorApp.Program.Main(String[] args)
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

The error occurs in Visual Studio and in LinqPad but it doesn't occur to my colleague.

I thought there could have been some kind of conflict with .NET 4.5 dev preview so I uninstalled it but without any benefit.

Thanks

2
  • are you referencing .net 4.5? Commented Mar 20, 2012 at 13:16
  • no i'm not. but the same bin folder runs "as is" on my colleague workstation Commented Mar 20, 2012 at 13:17

2 Answers 2

2

The ASP.NET Web API Beta is explicitly not compatible with the .NET Framework 4.5 Developer Preview. See http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253802.

I would recommend uninstalling both and reinstalling the Web API after cleaning out both. I don't think uninstalling .NET 4.5 after installing Web API will do the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

This is partly correct: I uninstalled Visual Studio 11 DP and .NET 4.5. After that I repaired VS2010 and everything was working. Thanks
0

It is possible to use pre-RTM WebAPI after you have installed VS2012. Add the following to your app/web.config

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0 - 2.0.0.0" newVersion="2.0.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

The problem is that the RTM version of System.Net.Http overrides the pre-RTM version because the newer version is in the GAC and the assy discovery prefers the newer version. Even if you explicity file reference the older version (grrr).

The NewtonSoft entry isn't strictly necessary...

Anyway this has worked for us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.