dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.08k stars 2.03k forks source link

The number of generic arguments provided doesn't equal the arity of the generic type definition. (Parameter 'instantiation') #9203

Open octavian-niculescu10 opened 18 hours ago

octavian-niculescu10 commented 18 hours ago

Hey, So I have a simple class which is structured like this:

public class MyClass<GClass> : IType where GClass : TClass, new()
{
    public GClass Instance { get; set; }
}

For this, I will get:

Orleans.Serialization.CodecNotFoundException : Could not find a copier for type MyClass`1[TClass].

if I will use GenerateSerializer so it generates the Copier, like this:

[GenerateSerializer]
public class MyClass<GClass> : IType where GClass : whatever, new()
{
    [Id(0)]
    public GClass Instance { get; set; }
}

Then I will get:

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

Stack Trace: 
  RuntimeType.MakeGenericType(Type[] instantiation)
  CodecProvider.CreateCopierInstance(Type fieldType, Type searchType) line 631
  CodecProvider.CreateCopierInstance(Type fieldType, Type searchType) line 655
  CodecProvider.TryCreateCopier(Type fieldType) line 348
  CodecProvider.TryGetDeepCopier(Type fieldType) line 336
  CodecProvider.GetDeepCopier(Type fieldType) line 327
  CopyContext.DeepCopy[T](T value) line 263
  IDeepCopier.DeepCopy(Object input, CopyContext context) line 133
  UntypedCopierWrapper`1.DeepCopy(T original, CopyContext context) line 366
  IDeepCopier.DeepCopy(Object input, CopyContext context) line 123
  <7 more frames...>
  TestMethodCommand.RunTestMethod(TestExecutionContext context)
  TestMethodCommand.Execute(TestExecutionContext context)
  <>c__DisplayClass4_0.<PerformWork>b__0()
  <>c__DisplayClass1_0`1.<DoIsolated>b__0(Object _)
  ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  --- End of stack trace from previous location ---
  ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  ContextUtils.DoIsolated(ContextCallback callback, Object state)
  ContextUtils.DoIsolated[T](Func`1 func)
  SimpleWorkItem.PerformWork()

I am using Orleans 7.2.6.

Why is this happening and how can I fix it? Thanks.

ReubenBond commented 17 hours ago

@octavian-niculescu10 this is odd, are you sure you don't have an [Alias(...)] attribute on the class (or maybe a base class?). It's possible that there was a bug which has been fixed since 7.x.

octavian-niculescu10 commented 17 hours ago

@ReubenBond I don't, I did a search in the whole project for it