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

Missing arity check in CodecProvider.cs #9268

Open
shalabala opened this issue Dec 17, 2024 · 0 comments
Open

Missing arity check in CodecProvider.cs #9268

shalabala opened this issue Dec 17, 2024 · 0 comments

Comments

@shalabala
Copy link

Orleans version: 9.0.1

in Orleans.Serialization.Serializers.CodecProvider.cs on lines 495-507:

 private IFieldCodec CreateCodecInstance(Type fieldType, Type searchType)
 {
     if (searchType == ObjectType)
         return _objectCodec;

     object[] constructorArguments = null;
     if (_fieldCodecs.TryGetValue(searchType, out var codecType))
     {
         if (codecType.IsGenericTypeDefinition)
         {
             codecType = codecType.MakeGenericType(fieldType.GetGenericArguments());
         }
     //...

this throws an exception if the codec type's arity and the field type's arity aren't matching.

In our concrete case the field type inherits from Collection<>, no codec is found (we use json serialization) and a search with the base type is conducted on CodecProvider.cs line 546. Then on line 505 the following error is thrown:

System.ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition. (Parameter 'instantiation').

Solution would be in my opinion to only enter the if branch if the arity matches, i.e.

 if (codecType.IsGenericTypeDefinition && codecType.GetGenericArguments().Length == fieldType.GetGenericArguments().Length)
 {
     codecType = codecType.MakeGenericType(fieldType.GetGenericArguments());
 }

Since there is no guarantee, that the base type's arity is equal to the inheriting type's. But im not entirely sure.

As far as i could descern this problem is also related to #8817 and #8347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant