Description
When using DispatchProxy for an interface which have an init property, it will throw TypeLoadException.
Reproduction Steps
class ClassTestI : DispatchProxy
{
protected override object? Invoke(MethodInfo? targetMethod, object?[]? args)
{
throw new NotImplementedException();
}
}
[Test]
public void Test(){
DispatchProxy.Create<TestI, ClassTestI>();
}
interface TestI
{
public int MyProperty { get; set; }
}
interface TestI
{
public int MyProperty { get; init }
}
Expected behavior
It Should success to create an object which implement the TestI interface
Actual behavior
System.TypeLoadException : Signature of the body and declaration in a method implementation do not match. Type: 'generatedProxy_1'. Assembly: 'ProxyBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.Emit.RuntimeTypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.RuntimeTypeBuilder.CreateTypeInfoImpl()
at System.Reflection.Emit.TypeBuilder.CreateType()
at System.Reflection.DispatchProxyGenerator.ProxyBuilder.CreateType()
at System.Reflection.DispatchProxyGenerator.ProxyAssembly.GenerateProxyType(Type baseType, Type interfaceType, String interfaceParameter, String proxyParameter)
at System.Reflection.DispatchProxyGenerator.ProxyAssembly.GetProxyType(Type baseType, Type interfaceType, String interfaceParameter, String proxyParameter)
at System.Reflection.DispatchProxyGenerator.CreateProxyInstance(Type baseType, Type interfaceType, String interfaceParameter, String proxyParameter)
at System.Reflection.DispatchProxy.Create[T,TProxy]()
Regression?
No response
Known Workarounds
Change the Property from {get; init;} to {get; set;} in the interface
Configuration
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Windows11
Other information
No response
Description
When using
DispatchProxyfor an interface which have an init property, it will throwTypeLoadException.Reproduction Steps
Expected behavior
It Should success to create an object which implement the
TestIinterfaceActual behavior
Regression?
No response
Known Workarounds
Change the Property from
{get; init;}to{get; set;}in the interfaceConfiguration
Windows11
Other information
No response