dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.28k stars 4.73k forks source link

DispatchProxy invoke method returning GenericType with constraint TypeLoadException #94096

Open zszabo79 opened 1 year ago

zszabo79 commented 1 year ago

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

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.

Issue Details
### 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. 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. 2. Wrap it to a proxy using the DispatchProxy class. 3. Call the one function of theese. ### Expected behavior DispatchProxy can handle functions with generic parameter and return types (like the old RealProxy). ### Actual behavior DispatchProxy can't handle functions with generic parameter and return types (like the old RealProxy). ### Regression? _No response_ ### Known Workarounds Unfortunally I don't know any workaround. Maybe you can help me. ### Configuration _No response_ ### Other information _No response_
Author: zszabo79
Assignees: -
Labels: `area-System.Reflection`
Milestone: -
steveharter commented 1 year ago

You promised repairing would be a milestone for .NET 5, but the bug still exists.

This was not promised. It was moved to v5 for further consideration and like many other issues moved to future based on schedule and\or cost:benefit. See https://github.com/dotnet/runtime/issues/31485#issuecomment-601392297

However, we can re-evaluate the cost:benefit for the current release and determine the effort to lift these constraints into proxies.

zszabo79 commented 1 year ago

Thank you for your attention to me, would be good to solve it in the next releases, because we had to remove generic constraints to use proxies. Generally we have to choose between incomplete code and proxies. The .NET standard basic language elements could be supported by .NET framework built in proxies