-
-
Notifications
You must be signed in to change notification settings - Fork 753
Closed
Description
environments:
- Version used: 2.2.60
- Runtime: .NET Core
Bug description
Generate process does not collect generic type definition, that defined outside target project.
Repro steps
- There are two projects, MyApp.Models.csproj and MyApp.Shared.csproj. MyApp.Models refers to MyApp.Shared.
MyApp.Models has generic type definition, that MyApp.Shared indirectly references.
in MyApp.Models.csproj
[MessagePackObject()]
public class UserInventoryChanges
{
[Key(0)] public InventoryChangedValue<int> Items { get; set; }
[Key(1)] public InventoryChangedValue<Currency> Currencies { get; set; }
}
[MessagePackObject()]
public class InventoryChangedValue<T>
{
[Key(0)] public T Value { get; set; }
}in MyApp.Shared.csproj
[MessagePackObject()]
public class Dummy
{
[Key(0)] public UserInventoryChanges _field { get; set; }
}- Run mpc.exe against MyApp.Shared.csproj.
dotnet mpc -i ./MyApp.Shared.csproj -o ./MessagePackGenerated/GeneratedResolver.cs -c MPC -r GeneratedResolver
The generated file does not contain theInventoryChangedValueFormatter<T>.
Expected behavior
The generated file contains formatter for generic type definition, that defined outside target project (InventoryChangedValueFormatter<T>).
Actual behavior
not so.
Additional context
I got the expected result by modifying it to collect the OriginalDefinition when it was a generic type.
// Generic types
if (type.IsDefinition)
{
this.CollectGenericUnion(type);
this.CollectObject(type);
return;
}
else
{
// Collect substituted types for the properties and fields.
// NOTE: It is used to register formatters from nested generic type.
// However, closed generic types such as `Foo<string>` are not registered as a formatter.
GetObjectInfo(type);
// Collect generic type definition, that is not collected when it is defined outside target project.
CollectCore(type.OriginalDefinition);
}