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

AssemblyEventRegistry throws exceptions when the assembly contains more than one lambda expression #12

Closed
tomasaschan opened this issue Oct 3, 2017 · 0 comments · Fixed by #16
Labels

Comments

@tomasaschan
Copy link
Owner

If the referred assembly contains more than one lambda expression, the generated closure classes have the same name, and therefore the dictionary construction throws.

We should be able to handle this case without an exception - and, in general, give a better exception message than the currently pretty non-descript one (included at the bottom).

public class Repro
{
    private class FooContainer
    {
        private Func<object, bool> Foo = _ => true;
    }

    private class BarContainer
    {
        private Func<object, bool> Bar = _ => false;
    }

    [Fact]
    public void AssemblyRegistryThrows()
    {
        var registry = new AssemblyEventRegistry(typeof(Repro));
    }
}

System.ArgumentException : An item with the same key has already been added. Key: <>c
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector) at RdbmsEventStore.EventRegistry.AssemblyEventRegistry..ctor(Type markerType, Func2 namer, Func`2 inclusionPredicate) in C:\Work\Deloitte\EventSourcing.POC\src\RdbmsEventStore\EventRegistry\AssemblyEventRegistry.cs:line 25
at RdbmsEventStore.EventRegistry.AssemblyEventRegistry..ctor(Type markerType) in C:\Work\Deloitte\EventSourcing.POC\src\RdbmsEventStore\EventRegistry\AssemblyEventRegistry.cs:line 10
at RdbmsEventStore.Tests.Repro.AssemblyRegistryThrows() in C:\Work\Deloitte\EventSourcing.POC\src\RdbmsEventStore.Tests\Repro.cs:line 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant