0

これは典型的な「dev では動作するが、prod では動作しない」シナリオですが、修正するには、prod で動作しない理由を特定する必要があります。オブジェクト グラフを返す比較的単純な Web API 呼び出しがあります。

public class ValuesController : ApiController
{
    public TimeSeriesData GetValues(string id) { /* get from database */ }
}

私のクラス

public class TimeSeriesData
{
    public string Name { get; set; }
    public List<Foo> KPIs { get; set; }
}

public class Foo
{
    public string Name { get; set; }
    public List<Bar> Values { get; set; }
}

public class Bar
{
    public double Actual { get; set; }
    public double Target { get; set; }
}

これらのクラスはすべて、必要に応じて で装飾されてDataContractDataMemberます (スペースを節約するためにこれを省略しています)。サービスはローカルで動作し、問題のサーバーと同じはずの別の製品環境を含む他の環境で動作します。

次のスタック トレースを取得します。

{"Message":"An error has occurred.",
"ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"ExceptionType":"System.InvalidOperationException",
"StackTrace":null,
"InnerException":
    {"Message":"An error has occurred.",
    "ExceptionMessage":"Error while copying content to a stream.",
    "ExceptionType":"System.Net.Http.HttpRequestException",
    "StackTrace":null,
    "InnerException":
        {"Message":"An error has occurred.",
        "ExceptionMessage":"Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, 
            Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. 
            The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)",
        "ExceptionType":"System.IO.FileLoadException",
        "StackTrace":"   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
            at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociateMetadataTypeFromAttribute(Type type)
            at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(TKey key)
            at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
            at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[T](Type type)
            at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(TKey key)
            at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
            at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
            at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
            at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteStartArray(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
            at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
            at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
            at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value)
            at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value)
            at System.Net.Http.Formatting.JsonMediaTypeFormatter.<>c__DisplayClassd.<WriteToStreamAsync>b__c()
            at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)"}}}

奇妙なことに、このサーバーでは他の Web API 呼び出しが機能しますが、それらははるかに単純です。たとえば、文字列のリストを取得できます。

誰でもこれに遭遇したか、何か提案がありますか?

4

0 に答える 0