Add field to schema fails with exception even latest version

I’m submitting a…

[x ] Regression (a behavior that stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Documentation issue or request

Current behavior

I got latest code from master, run debugging with vs 2017 and attempting to add new filed to existing schema (pages schema) and got error message: "Failed to add field. Please reload’.
The exception is: {System.InvalidOperationException: Could not find subtype of ‘FieldPropertiesDto’ with discriminator ‘String’.
at NJsonSchema.Converters.JsonInheritanceConverter.GetDiscriminatorType(JObject jObject, Type objectType, String discriminatorValue)
at NJsonSchema.Converters.JsonInheritanceConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) in //Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:line 2159
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) in /
/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:line 1032
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:line 2386
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<g__Bind|0>d.MoveNext()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()}

Expected behavior

To be able to add field to schema.

Minimal reproduction of the problem

Go to schema. Use the ‘Add field’ button and attempt to add a field with any types.

Environment

  • [ ] Self hosted with docker
  • [x ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Browser:

  • [x ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

Sorry, I cannot reproduce it. I remember the error, but it has been fixed a week ago or two. Are you sure that you have the latest master version?

Yes, I pull the master and did follow the build documentation but got that above exceptiob. Could you please tell me where to check it? Sorry I’m new to squidex

There is a class called MyJsonInheritanceConverter.cs in the Squidex main project. Can you post the content here?

It doesn’t hit this class:

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright © Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using NJsonSchema.Converters;

namespace Squidex.Areas.Api.Controllers
{
public class MyJsonInheritanceConverter : JsonInheritanceConverter
{
private readonly IDictionary<string, Type> mapping;
private readonly Type baseType;

    public MyJsonInheritanceConverter(string discriminator, Type baseType)
        : base(baseType, discriminator)
    {
        this.baseType = baseType;
    }

    public MyJsonInheritanceConverter(string discriminator, Type baseType, IDictionary<string, Type> mapping)
        : this(discriminator, baseType)
    {
        this.mapping = mapping;
    }

    public override string GetDiscriminatorValue(Type type)
    {
        var result = type.Name;

        if (baseType != null)
        {
            var baseName = baseType.Name;

            if (result.EndsWith(baseName, StringComparison.CurrentCulture))
            {
                return result.Substring(0, result.Length - baseName.Length);
            }
        }

        return mapping?.FirstOrDefault(x => x.Value == type).Key ?? result;
    }
}

}

Could it be related to dotnet core version? I’m using 2.2.101

Thanks & regards

I still think that you do not have the latest version: https://github.com/Squidex/squidex/blob/master/src/Squidex/Areas/Api/Controllers/MyJsonInheritanceConverter.cs :wink:

Pull it from master

Got it. My fork just up to this: Discriminator fixes for json schema.
I sync-ed upstream and got the latest. Thanks for your help Sebastian