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

Invalid code generation on fields of interface type #127

Closed
rogeralsing opened this issue Nov 12, 2016 · 5 comments
Closed

Invalid code generation on fields of interface type #127

rogeralsing opened this issue Nov 12, 2016 · 5 comments
Labels

Comments

@rogeralsing
Copy link
Collaborator

rogeralsing commented Nov 12, 2016

If a field is of an interface type, Wire currently tries to fetch the fields of that type, which is invalid.
interface types should just act as an object field and let the concrete content of the field decide how to serialize the data.

akkadotnet/akka.net#2365

@kantora
Copy link

kantora commented Nov 23, 2016

And what is wrong always work only with contents end-types (not declared field/property types)?

@rogeralsing
Copy link
Collaborator Author

It uses both the field type and the content type.

  • if they both match, it can optimize the flow.
  • If they differ, there is another path.

the problem currently with the interfaces in the fields, is that the code generator tries to do things that are not possible on an interface type.

@rogeralsing
Copy link
Collaborator Author

I have added tests for this,
The tests however pass and the interface field is serialized just fine.
I need to create tests for the specific messages in Akka.NET that uses interface fields to see why that fails.

@kantora
Copy link

kantora commented Nov 24, 2016

Maybe this can help. I've made some local modification in Wire to make exceptions give more data and managed to trace the problem.

Akka.Cluster.Tools.PublishSubscribe.Internal.Bucket has the field public readonly IImmutableDictionary<string, ValueHolder> Content.

The problem is in the Wire.SerializerFactories.ImmutableCollectionsSerializerFactory.BuildSerializer.

            var typeName = type.Name;
            var genericSufixIdx = typeName.IndexOf('`');
            typeName = genericSufixIdx != -1 ? typeName.Substring(0, genericSufixIdx) : typeName;
            var creatorType =
                Type.GetType(
                    ImmutableCollectionsNamespace + "." + typeName + ", " + ImmutableCollectionsAssembly, true);

For this field creatorType tries to load type System.Collections.Immutable.IImmutableDictionary, System.Collections.Immutable and there is no such type (Type load exception).

Unfortunately, I don't have enough understanding of the code to get the meaning of such type name conversion (as you are not guaranteed to have a type with the same name as generic, but without generic parameters).

@rogeralsing
Copy link
Collaborator Author

I will continue to dig in this.
It could be that Wire incorrectly encodes the type of the payload as the interface type, and once it tries to deserialize, it might try to create an instance of the interface.
Which is ofcourse not possible.

I will keep updating here.

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

No branches or pull requests

2 participants