2016-10-12 3 views
1

Xamarin.Android 프로젝트의 PCL 프로젝트에서 httpClient.PostAsJsonAsync() 또는 httpClient.PutAsJsonAsync()을 수행 할 때 다음 오류가 발생합니다.'System.Net.Http.FormattingUtilities'유형을로드 할 수 없습니다

오류 :

System.TypeLoadException: Could not load type 'System.Net.Http.FormattingUtilities' from assembly 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

이 오류는이 코드에서 발생

public async Task<User> CreateUser(string name, string email, string password) 
    { 
     try 
     { 
      User user = new User(); 
      user.Name = name; 
      user.Email = email; 
      user.Password = password; 

      var response = await _client.PostAsJsonAsync("myUrl", user); // error on this line 
      string content = await response.Content.ReadAsStringAsync(); 

      return string.IsNullOrEmpty(content) ? new User() : 
       JsonConvert.DeserializeObject<User>(content); 
     } 
     catch (JsonReaderException ex) 
     { 
      throw ex; 
     } 
     catch (WebException ex) 
     { 
      throw ex; 
     } 
     catch (Exception ex) 
     { 
      throw ex; // ex is null here 
     } 
} 
+0

web.ui proj (또는 프론트 엔드 프로젝트의 다른 이름) – Nathan

+0

아래 패키지 및 bin 및 obj 폴더의 모든 파일을 삭제하거나 와 같이 에 어셈블리 종속성 구성을 추가하십시오. Nathan

+0

@NathanGong , 아니, 그건 효과가 없었어. – lpfx

답변

1

난 포기.

string json = JsonConvert.SerializeObject(user); 
var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); 
var response = await _client.PostAsync(myUrl, stringContent); 

지금 작동 :

나는 그것을 변경했습니다.

관련 문제