dotnet / dotnet/orleans

[KnownBaseType] does not generate serializer for subtypes?

Open
#7,645 4 comments 0 reactions 1 assignee Claimed by @ReubenBond View on GitHub
area-codegen Needs: investigation 🔍
Dominant language
C#
Stars
10.9k
Forks
2.1k
Avg merge
15h 1m
Merged PRs (30d)
345

Description

As [doc ](https://dotnet.github.io/orleans/docs/grains/code_generation.html#generate-serializers-for-all-subtypes) says

> Adding [KnownBaseType] to an interface or class instructs the code generator to generate serialization code for all types which inherit/implement that type.

I have an interface in assembly annotated with `[KnownBaseType]`.
And there is a class in a different assembly implementing this interface.

After successfully compilation, I checked the binary containing the class, there is no serializer generated.
Only if `[Serializable]` annotation is added for this class, serializer is generated.

It seems `[KnownBaseType]` does not work as the document stats?

Both assemblies have the following reference.



all
runtime; build; native; contentfiles; analyzers; buildtransitive

The following screenshot shows the serializer generated when `[Serializable]` is added
![image](https://user-images.githubusercontent.com/2765840/159599855-052bf721-b776-4f46-807e-775e3ae95d8a.png)

The following screenshot shows the serializer is missing when `[Serializable]` is removed; but the class implements an interface annotated with `[KnownBaseType]` from another assembly.
![image](https://user-images.githubusercontent.com/2765840/159600425-a1e83a84-18bc-4fb9-bfe6-d09dd0742cd6.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.