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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
@@ -90,6 +95,14 @@ private Type FindType(string name)
return GenericIListType.MakeGenericType(FindType(itemTypeName));
}

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 Note

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

Check notice

Code scanning / CodeQL

Generic catch clause Note

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 Warning

Variable
arrSchema
may be null at this access because of
this
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 Warning

Variable
mapSchema
may be null at this access because of
this
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