2012-03-20 3 views
2

Asp.NET WebAPI 모듈을 사용하려고하는데 이상한 오류가 발생합니다. 나는이 간단한 프로그램을 실행하려고하면 :ASP.NET WebApi - HttpClient - 메서드를 찾을 수 없습니다.

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

을이 오류가 있습니다.

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

Visual Studio 및 LinqPad에서 오류가 발생하지만 내 동료에게는 발생하지 않습니다.

.NET 4.5 개발 미리보기와 충돌이있을 수 있다고 생각했기 때문에 제거했지만 이점은 없었습니다.

감사

+0

.net 4.5를 참조하고 있습니까? –

+0

아니에요. 하지만 동일한 bin 폴더가 동료 워크 스테이션에서 "있는 그대로"실행됩니다. – Kralizek

답변

2

은 ASP.NET 웹 API 베타 명시 적으로 .NET 프레임 워크 4.5 개발자 미리보기와 호환되지 않습니다. http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253802을 참조하십시오.

둘 다 제거한 후 웹 API를 다시 설치하는 것이 좋습니다. 나는 웹을 설치하는 이후에 .NET을 제거하지 않을 것이라고 생각한다. 은 트릭을 할 것이다.

+0

부분적으로 정확합니다 : Visual Studio 11 DP 및 .NET 4.5를 제거했습니다. 그 후 VS2010을 수리하고 모든 것이 잘 작동하고있었습니다. 감사합니다. – Kralizek

0

VS2012를 설치 한 후 pre-RTM WebAPI를 사용할 수 있습니다. 앱에서 /의 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> 

문제는 최신 버전의 GAC에 있으며 ASSY 발견은을 선호하기 때문에 System.Net.Http의 RTM 버전이 사전 RTM 버전이 우선이다 최신 버전. 비록 당신이 explicity 파일 참조 이전 버전 (grrr).

NewtonSoft 항목은

어쨌든이 우리를 위해 일했다 ... 엄격하게 할 필요가 없습니다.

관련 문제