UndefinedSchemaIdHandling

Sep 25, 2009 at 1:43 PM

 When I use the

jsonSchemaGenerator.Generate(type); 
I am getting following exception. I have tried all the three values from enum variable 
UndefinedSchemaIdHandling 

on the generator class .

I agree in my class hierarchy there is recursive inclusion of the class mentioned in the exception.

How to resolve this?

System.Exception was unhandled
  Message="Unresolved circular reference for type 'ControlFlowItemCollection'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property."
  Source="Newtonsoft.Json"
  StackTrace:
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 234
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 297
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 275
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 297
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 275
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.GenerateInternal(Type type, Boolean valueRequired) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 297
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.Generate(Type type, JsonSchemaResolver resolver, Boolean rootSchemaNullable) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 167
       at Newtonsoft.Json.Schema.JsonSchemaGenerator.Generate(Type type) in D:\SantoshDM\20090918\svn\JamesonKing-Json.Net\trunk\Src\Newtonsoft.Json\Schema\JsonSchemaGenerator.cs:line 128
       at TemplateGenerator.Program.Main(String[] args) in D:\SantoshDM\20090918\svn\DataManager\TemplateGenerator\Program.cs:line 60
  InnerException:

Coordinator
Oct 3, 2009 at 12:48 AM

Could you add the code for your class that is causing the problem?

Oct 6, 2009 at 11:05 AM
// Driver function I have written, which results in exception
public class A
{
    void f()
    {
        Type type = Type.GetType("Workspace");
        if (type == null)
        {
            Console.Write("Class not found\n");
        }
        else
        {
            Newtonsoft.Json.Schema.JsonSchemaGenerator jsonSchemaGenerator = new Newtonsoft.Json.Schema.JsonSchemaGenerator();

            //jsonSchemaGenerator.UndefinedSchemaIdHandling = Newtonsoft.Json.Schema.UndefinedSchemaIdHandling.UseAssemblyQualifiedName;
            Newtonsoft.Json.Schema.JsonSchema jsonSchema = jsonSchemaGenerator.Generate(type);

            using (StreamWriter wr = new StreamWriter(CommandLine["JsonSchemaFileName"]))
            {
                using (JsonWriter writer = new JsonTextWriter(wr))
                {
                    jsonSchema.WriteTo(writer);
                }
            }
        }
    }
}



// class declarions are given below.

public class DMDSLBase
{
    public String Comment;
}
//Sensor has been renamed to Workspace
public class Workspace : DMDSLBase
{
    public ControlFlowItemCollection Jobs = new ControlFlowItemCollection();
}

//-----------------------------------------------------------------
#region Control Flow Items

public class ControlFlowItemBase : DMDSLBase
{
    public String Name;

}

public class ControlFlowItem : ControlFlowItemBase//A Job
{
    public TaskCollection Tasks = new TaskCollection();
    public ContainerCollection Containers = new ContainerCollection();
}

//Jobs
public class ControlFlowItemCollection : List<ControlFlowItem>
{
}

public class Task : ControlFlowItemBase
{
    public DataFlowTaskCollection DataFlowTasks = new DataFlowTaskCollection();
    public BulkInsertTaskCollection BulkInsertTask = new BulkInsertTaskCollection();
}

public class TaskCollection : List<Task>
{
}

public class Container : ControlFlowItemBase
{
    public ControlFlowItemCollection ContainerJobs = new ControlFlowItemCollection();
}

public class ContainerCollection : List<Container>
{
}

public class DataFlowTask_DSL : ControlFlowItemBase
{
}

public class DataFlowTaskCollection : List<DataFlowTask_DSL>
{
}

public class SequenceContainer_DSL : Container
{

}

public class BulkInsertTaskCollection : List<BulkInsertTask_DSL>
{
}

public class BulkInsertTask_DSL
{
}

 

Coordinator
Oct 15, 2009 at 4:45 AM

This is now fixed in the latest version of the source code on CodePlex.