Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remoting type checking #21700

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix remoting type checking #21700

wants to merge 1 commit into from

Conversation

Darkar25
Copy link

This PR is a bug report and a fix proposal at the same time.

The bug

Remoting method calls on a generic types produce the "RemotingException: Cannot cast from client type 'X' to server type 'Y'" if the type has 2+ layers deep generic arguments, such as A<B<C>>
The GetTypeNameFromAssemblyQualifiedName method would incorrectly trim the type name and that will cause the CastTo method to return null and throw the exception down the line. Example of such incorrect trimming:
A'1[[B'1[[C, assembly]], assembly]], assembly
becomes
A'1[[B'1[[C, assembly]]
This is incorrect and would not match any type ever. It should instead be trimmed to this:
A'1[[B'1[[C, assembly]], assembly]]

The fix

The GetTypeNameFromAssemblyQualifiedName method should use the LastIndexOf instead of IndexOf when searching for "]]"

Warning

I tested this fix only on Windows platform in kind of very specific use case so i do not guarantee that this fix is universal for everyone and would not break anything. Someone test my fix properly if you able, please.

Method calls on a generic types produce the "RemotingException: Cannot cast from client type 'X' to server type 'Y'" if they have 2+ layers deep generic arguments, such as A<B<C>>
The GetTypeNameFromAssemblyQualifiedName would incorrectly trim the type name and that will cause the CastTo method to return null and throw the exception down the line.
Example of such incorrect trimming:
A`1[[B`1[[C, assembly]], assembly]], assembly
becomes
A`1[[B`1[[C, assembly]]
This is incorrect and would not match any type ever. It should instead be trimmed to this:
A`1[[B`1[[C, assembly]], assembly]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant