© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
34 replies
SWEETPONY

❔ How to fix "Target runtime doesn't support covariant types in overrides?

I have Builder, let's see code:
public abstract class UISchemaBuilderBase
{
   protected readonly UISchemaSpecification UiSchemaSpecification;

   public UISchemaSpecification Builder() =>
      UiSchemaSpecification;

   public virtual UISchemaBuilderBase AddBoolean(
       string fieldName,
       string groupName = null)

   {
       .. some logic
    
       UiSchemaSpecification.Properties[ fieldName ] = schema;
       return this;
   }
}

public class UISchemaBuilder : UISchemaBuilderBase
{
    public UISchemaBuilder() : base(new UISchemaSpecification()) { }

    public UISchemaGroupBuilder StartGroup(string name)
    {
        UiSchemaSpecification.ParsecMetadata ??= new();
        UiSchemaSpecification.ParsecMetadata.Groups ??= new();
        UiSchemaSpecification.ParsecMetadata.Groups.Add( new(name) );

        return new UISchemaGroupBuilder(name, this, UiSchemaSpecification);
    }
}

public class UISchemaGroupBuilder : UISchemaBuilderBase
{
    private readonly string _name;
    private readonly UISchemaBuilder _schemaBuilder;

    public UISchemaGroupBuilder(
       string name,
       UISchemaBuilder schemaBuilder,
       UISchemaSpecification specification)
       : base(specification)
    {
        _name = name;
        _schemaBuilder = schemaBuilder;
    }

   public override UISchemaGroupBuilder AddBoolean(
       string fieldName,
       string fieldTitle,
       string groupName = null)
    {
        base.AddBoolean(fieldName, fieldTitle, _name);
        return this;
    }
}
public abstract class UISchemaBuilderBase
{
   protected readonly UISchemaSpecification UiSchemaSpecification;

   public UISchemaSpecification Builder() =>
      UiSchemaSpecification;

   public virtual UISchemaBuilderBase AddBoolean(
       string fieldName,
       string groupName = null)

   {
       .. some logic
    
       UiSchemaSpecification.Properties[ fieldName ] = schema;
       return this;
   }
}

public class UISchemaBuilder : UISchemaBuilderBase
{
    public UISchemaBuilder() : base(new UISchemaSpecification()) { }

    public UISchemaGroupBuilder StartGroup(string name)
    {
        UiSchemaSpecification.ParsecMetadata ??= new();
        UiSchemaSpecification.ParsecMetadata.Groups ??= new();
        UiSchemaSpecification.ParsecMetadata.Groups.Add( new(name) );

        return new UISchemaGroupBuilder(name, this, UiSchemaSpecification);
    }
}

public class UISchemaGroupBuilder : UISchemaBuilderBase
{
    private readonly string _name;
    private readonly UISchemaBuilder _schemaBuilder;

    public UISchemaGroupBuilder(
       string name,
       UISchemaBuilder schemaBuilder,
       UISchemaSpecification specification)
       : base(specification)
    {
        _name = name;
        _schemaBuilder = schemaBuilder;
    }

   public override UISchemaGroupBuilder AddBoolean(
       string fieldName,
       string fieldTitle,
       string groupName = null)
    {
        base.AddBoolean(fieldName, fieldTitle, _name);
        return this;
    }
}

So implemented code allows use to do this:

var builder = new UISchemaBuilder()
  .StartGroup("groupName")
    .AddBoolean()
  .EndGroup()
  .StartGroup("anotherGroupName")
    .AddBoolean()
  .EndGroup()
  .Build();
var builder = new UISchemaBuilder()
  .StartGroup("groupName")
    .AddBoolean()
  .EndGroup()
  .StartGroup("anotherGroupName")
    .AddBoolean()
  .EndGroup()
  .Build();
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Target runtime doesn't support default interface implementation.
C#CC# / help
4y ago
❔ Covariant Interface Return
C#CC# / help
3y ago
MSBuild doesn't detect files created using Target
C#CC# / help
2y ago
✅ Covariant return type properties
C#CC# / help
2y ago