2016-09-06 5 views
1

AutoRest를 사용하여 Swagger 정의 파일에서 REST API에 대한 C# 클래스를 자동 생성합니다.JsonConverter 목록에 Iso8601TimeSpanConverter를 추가하면 ArrayTypeMismatch 예외가 발생합니다.

문제는 클라이언트 클래스 초기화 Methos는 실행될 때, 다음 코드에 ArrayTypeMismatch 예외가 발생한다는 것이다 : 코드

SerializationSettings = new JsonSerializerSettings 
{ 
    Formatting = Formatting.Indented, 
    DateFormatHandling = DateFormatHandling.IsoDateFormat, 
    DateTimeZoneHandling = DateTimeZoneHandling.Utc, 
    NullValueHandling = NullValueHandling.Ignore, 
    ReferenceLoopHandling = ReferenceLoopHandling.Serialize, 
    ContractResolver = new ReadOnlyJsonContractResolver(), 
    Converters = new List<JsonConverter> 
     { 
      new Iso8601TimeSpanConverter() 
     } 
} 

기분을 상하게하는 부재가 Iso8601TimeSpanConverter가 JsonConverters 목록에 추가된다.

실제로이 오류는 VSIX 패키지에서이 코드를 실행할 때만 발생합니다. 독립 실행 형 앱에서는 정상적으로 작동합니다.

Newtonsoft.Json로드 및 충돌의 여러 버전과 관련이 있는지 궁금합니다.

아이디어가 있으십니까?

+0

예외 유형, 메시지, 내부 예외 및 추적을 포함하여 예외의 전체 ToString() 출력을 포함하도록 질문을 편집 할 수 있습니까? – dbc

+0

WPF DesginMode 안에이 예외가 있습니다! 불행히도 특별한 예외 메시지가 없습니다 :'System.ArrayTypeMismatchException occurred; HResult = -2146233085; 메시지 = 배열과 호환되지 않는 유형으로 요소에 액세스하려고 시도했습니다. 원본 = mscorlib' 'StackTrace : System.Collections.Generic.List'1.Add (T 항목) Client.WebApi.MyRestApi.Initialize()' – Marcel

답변

0

동일한 문제가 발생했지만 app.config를 사용하여 Newtonsoft.Json 바인딩을 통합하여 해결할 수 있습니다.

<configuration> 
    <runtime> 
    <assemblyBinding> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

문제는 Iso8601TimeSpanConverter 당신이 AutoRest에 사용하는 것보다 JsonConverter의 다른 버전을 상속 될 수 있다는 점이다.