Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guid type causes KeyNotFoundException in calls to CreateDeserializerOnly<T> or CreateGenericDeserializerOnly #987

Closed
sokhalsa opened this issue Mar 5, 2015 · 5 comments
Labels
HDInsight Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@sokhalsa
Copy link

sokhalsa commented Mar 5, 2015

When attempting to call AvroSerializer.CreateDeserializerOnly or AvroSerializer.CreateGenericDeserializerOnly with a writer schema for a type that contains a Guid, a KeyNotFoundException ("The given key was not present in the dictionary.") error is thrown in JsonSchemaBuilder.CreatePrimitiveTypeSchema because "System.Guid" is not a key in the PrimitiveRuntimeType dictionary.

The stack trace is:

at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.CreatePrimitiveTypeSchema(String type, Dictionary2 attributes) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 410
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.ParsePrimitiveTypeFromString(String token) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 382
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.Parse(JToken token, NamedSchema parent, Dictionary2 namedSchemas) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 105 at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.ParseRecordField(JObject field, NamedSchema parent, Dictionary2 namedSchemas, Int32 position) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 349
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.<>c__DisplayClass3.b__2(JToken field, Int32 index) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 318
at System.Linq.Enumerable.d__72.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at Microsoft.Hadoop.Avro.Schema.JsonExtensions.ReadArrayProperty[T](JToken token, String propertyName, Boolean isOptional, Func3 func) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonExtensions.cs:line 195 at Microsoft.Hadoop.Avro.Schema.JsonExtensions.OptionalArrayProperty[T](JToken token, String propertyName, Func3 func) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonExtensions.cs:line 78
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.ParseRecordType(JObject record, NamedSchema parent, Dictionary2 namedSchemas) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 309 at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.ParseJsonObject(JObject token, NamedSchema parent, Dictionary2 namedSchemas) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 140
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.Parse(JToken token, NamedSchema parent, Dictionary`2 namedSchemas) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 88
at Microsoft.Hadoop.Avro.Schema.JsonSchemaBuilder.BuildSchema(String schema) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\Schema\JsonSchemaBuilder.cs:line 71
at Microsoft.Hadoop.Avro.AvroSerializer.CreateForCore[T](String writerSchema, AvroSerializerSettings settings) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\AvroSerializer.Static.cs:line 177
at Microsoft.Hadoop.Avro.AvroSerializer.CreateDeserializerOnly[T](String writerSchema, AvroSerializerSettings settings) in d:\Git\WindowsAzure\azure-sdk-for-net\src\HDInsight\Microsoft.Hadoop.Avro\AvroSerializer.Static.cs:line 98

chuanboz added a commit to chuanboz/HDInsight that referenced this issue Mar 5, 2015
@sokhalsa
Copy link
Author

sokhalsa commented Mar 5, 2015

It looks like it has to do with multiple Guid members in a class causing JsonSchemaBuilder to the schema incorrectly.

Given the following class:

[System.Runtime.Serialization.DataContract]
    public class ClassOfGuid
    {
        [System.Runtime.Serialization.DataMember]
        public Guid PrimitiveGuid;

        [System.Runtime.Serialization.DataMember]
        public Guid AnotherPrimitiveGuid;
    }

A call to AvroSerializer.CreateDeserializerOnly will fail with a KeyNotFoundException. The following test case demonstrates that:

    [TestMethod]
    [TestCategory("CheckIn")]
    public void JsonSchemaBuilder_ClassOfGuidWriterSchema()
    {
        var settings = new Microsoft.Hadoop.Avro.AvroSerializerSettings();
        Microsoft.Hadoop.Avro.IAvroSerializer<ClassOfGuid> serializer = Microsoft.Hadoop.Avro.AvroSerializer.Create<ClassOfGuid>(settings);
        Microsoft.Hadoop.Avro.AvroSerializer.CreateDeserializerOnly<ClassOfGuid>(serializer.WriterSchema.ToString(), settings);
    }

@markcowl
Copy link
Member

@sokhalsa Thank you for the feedback. Assigned to the appropriate team

ogail added a commit that referenced this issue Jul 6, 2015
Test case for #1206.  Fails in the current build, but is fixed by proposed fix for #987
@jholovacs
Copy link

Was anything ever done with this? It's still open 2 years later.

@shahabhijeet
Copy link
Member

please reopen if this is still an issue.

@bsiegel bsiegel added the Service Attention Workflow: This issue is responsible by Azure service team. label Sep 26, 2018
@IvanDeev
Copy link

Looks like it wasn't fixed. Reproduces in Microsoft.Hadoop.Avro2 1.2.1 and microsoft.hadoop.avro-core 1.1.19. And I don't see Microsoft.Hadoop.Avro in azure-sdk-for-net now.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
HDInsight Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

6 participants