Navigation Menu

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

Generic method with differently named generic arguments to parent throws KeyNotFoundException #106

Closed
HelloKitty opened this issue Aug 4, 2015 · 4 comments · Fixed by #580
Labels
Milestone

Comments

@HelloKitty
Copy link

Issue: Throws KeyNotFoundException in https://github.com/castleproject/Core/blob/master/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs at method public Type[] GetGenericArgumentsFor(MethodInfo genericMethod)

Conditions: When Type name of generic type doesn't match the name of the Type in an interface.

Workaround: Change any generic Type names to match the name on the source interface.

This happens in Mono and .Net. If a generic method's generic Type name mismatches with its implemented name then this throws in Moq.

Original issues incorrectly posted on Moq's GitHub: here

HelloKitty added a commit to HelloKitty/GladNet3 that referenced this issue Aug 4, 2015
For more info on change, why test failed and how to avoid it again see:
castleproject/Core#106
@kkozmic-seek
Copy link

Hey @HelloKitty

Is this still an issue or was that MOQ specific?

@kkozmic kkozmic added this to the v3.4 milestone Sep 9, 2015
@kkozmic
Copy link
Contributor

kkozmic commented Sep 9, 2015

Also, if it's not and it's still an issue, can you elaborate on when the issue occurs. Posting a failing test would help.

@jonorossi
Copy link
Member

Based on other non-Castle GitHub issues others have linked here the problem is as the test below highlights, the interface and implementation generic arguments must have the same name otherwise DynamicProxy breaks:

public interface ITest
{
    void Hi<T>();
}
public class Test : ITest
{
    public void Hi<T2>()
    {
    }
}

[Test]
public void GenericMethodDifferentlyNamedGenericArguments()
{
    generator.CreateClassProxy(typeof(Test), new[] { typeof(ITest) }, new DoNothingInterceptor());
}

Failure:

System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
TearDown : System.NotSupportedException : Type 'Castle.Proxies.TestProxy' was not completed.

@jonorossi
Copy link
Member

Since this is a long standing defect and has a workaround, I'm removing it from the v4.0 milestone.

@jonorossi jonorossi removed this from the v4.0 milestone Jul 8, 2016
@jonorossi jonorossi changed the title Generic Method; Moq related. Generic method with differently named generic arguments to parent throws KeyNotFoundException Jul 11, 2016
@stakx stakx mentioned this issue May 31, 2018
@stakx stakx self-assigned this Aug 4, 2019
@stakx stakx removed the up-for-grabs label Aug 4, 2019
@stakx stakx removed their assignment Jan 6, 2021
@jonorossi jonorossi added this to the v5.0.0 milestone Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants