Skip to content

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

Closed

Description

@HelloKitty

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

Activity

  1. kkozmic-seek commented on Sep 8, 2015

    @kkozmic-seek

    Hey @HelloKitty

    Is this still an issue or was that MOQ specific?

  2. added this to the milestone on Sep 9, 2015
  3. kkozmic commented on Sep 9, 2015

    @kkozmic
    Contributor

    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.

  4. jonorossi commented on Jul 8, 2016

    @jonorossi
    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.
    
  5. jonorossi commented on Jul 8, 2016

    @jonorossi
    Member

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

  6. removed this from the v4.0 milestone on Jul 8, 2016
  7. changed the title [-]Generic Method; Moq related.[/-] [+]Generic method with differently named generic arguments to parent throws KeyNotFoundException[/+] on Jul 11, 2016
  8. self-assigned this
    on Aug 4, 2019
  9. removed their assignment
    on Jan 6, 2021
  10. added this to the v5.0.0 milestone on Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions