dotnet/runtime

DispatchProxy invoke method returning GenericType with constraint TypeLoadException

開放

#94,096 建立於 2023年10月27日

 (3 則留言) (0 個反應) (0 位負責人)C# (5,445 個分叉)batch import
area-System.Reflectionhelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Description

This bug has already been added as #31485, but unfortunatelly closed! You promised repairing would be a milestone for .NET 5, but the bug still exists.

DispatchProxy can't generate adequate proxy for classes that have functions with generic type parameters or return values (in case of they have generic constraints). For me it is urgent. Is there any workaround, or when will this bug be fixed?

The exception I get when I make dispatch proxy in .NET 6 is also System.TypeLoadException: 'GenericArguments[0], 'TEntity', on DataAccess.Interface.Repository.IEntityRepository`1[TEntity]' violates the constraint of type parameter 'TEntity'.'

Please see #31485 for details.

Reproduction Steps

  1. Make a class with some functions that have generic parameters or return values ** with generic constraints **.

  2. Wrap it to a proxy using the DispatchProxy class.

  3. Call one function of theese.

Expected behavior

DispatchProxy can handle functions with generic parameter and return types have generic constraints (like the old RealProxy).

Actual behavior

DispatchProxy can't handle functions with generic parameter and return types have generic constraints.

Regression?

No response

Known Workarounds

Unfortunally I don't know any workaround. Maybe you can help me.

Configuration

No response

Other information

No response

貢獻者指南