Skip to content

AVRO-4028: Avro.AvroException: Unable to find type 'IDictionary<string, Foo>' in all loaded assemblies#3072

Open
kkkars wants to merge 3 commits intoapache:mainfrom
kkkars:AVRO-4028-nested-dictionary
Open

AVRO-4028: Avro.AvroException: Unable to find type 'IDictionary<string, Foo>' in all loaded assemblies#3072
kkkars wants to merge 3 commits intoapache:mainfrom
kkkars:AVRO-4028-nested-dictionary

Conversation

@kkkars
Copy link

@kkkars kkkars commented Aug 7, 2024

What is the purpose of the change

This pull request improves type finding logic of ObjectCreator.cs helping to handle nested dictionaries (map in the map).
Fixes the issue https://issues.apache.org/jira/browse/AVRO-4028

Verifying this change

(Please pick one of the following options)

This change is a trivial rework. New test cases were added to an existing unit test (TestGetTypeAssignable(), ObjectCreatorTests.cs) to validate nested dictionaries are handled correctly.

Documentation

This pull request does not introduce a new feature

@github-actions github-actions bot added the C# label Aug 7, 2024

if (TryGetIDictionaryItemTypeName(name, out var itemTypesName))
{
var key = itemTypesName[0].GetType().Name;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic on the line 135 (if (name == t.Name || name == t.FullName ..) compare in case sensetive way. So it's not able to handle string (system name is String)

.GetType().Name helps to handle string type correctly (changing string to String).

That is not a flexible solution and it requires key to always be a string. Changing the type names comparing logic also does not sound like a good idea.

Comment on lines 295 to 297
catch
{
}

Check notice

Code scanning / CodeQL

Poor error handling: empty catch block

Poor error handling: empty catch block.
Comment on lines 295 to 297
catch
{
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
case Schema.Type.Array:
{
ArraySchema arrSchema = schema as ArraySchema;
Type itemSchema = GetType(arrSchema.ItemSchema);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [arrSchema](1) may be null at this access because of [this](2) assignment.
{
return FindType(named.Fullname);
MapSchema mapSchema = schema as MapSchema;
Type itemSchema = GetType(mapSchema.ValueSchema);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [mapSchema](1) may be null at this access because of [this](2) assignment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant