{"action":"created","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/426","repository_url":"https://api.github.com/repos/simpleinjector/SimpleInjector","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/426/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/426/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/426","id":233383030,"number":426,"title":"ToFriendlyName() fails on certain proxy-generated types.","user":{"login":"ptsteward","id":16625754,"avatar_url":"https://avatars3.githubusercontent.com/u/16625754?v=3","gravatar_id":"","url":"https://api.github.com/users/ptsteward","html_url":"https://github.com/ptsteward","followers_url":"https://api.github.com/users/ptsteward/followers","following_url":"https://api.github.com/users/ptsteward/following{/other_user}","gists_url":"https://api.github.com/users/ptsteward/gists{/gist_id}","starred_url":"https://api.github.com/users/ptsteward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptsteward/subscriptions","organizations_url":"https://api.github.com/users/ptsteward/orgs","repos_url":"https://api.github.com/users/ptsteward/repos","events_url":"https://api.github.com/users/ptsteward/events{/privacy}","received_events_url":"https://api.github.com/users/ptsteward/received_events","type":"User","site_admin":false},"labels":[{"id":197522066,"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/labels/bug","name":"bug","color":"fc2929","default":true},{"id":197524790,"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/labels/task","name":"task","color":"5319e7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/milestones/25","html_url":"https://github.com/simpleinjector/SimpleInjector/milestone/25","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/milestones/25/labels","id":2550473,"number":25,"title":"v4.0.8","description":"Patch release.","creator":{"login":"dotnetjunkie","id":1506621,"avatar_url":"https://avatars2.githubusercontent.com/u/1506621?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":2,"state":"open","created_at":"2017-05-30T13:18:30Z","updated_at":"2017-06-03T23:13:40Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2017-06-03T17:22:59Z","updated_at":"2017-06-04T08:54:34Z","closed_at":"2017-06-03T23:13:40Z","body":"I came across an interesting issue when try to override a batch registration with a mock implementation produced by NSubstitute. The generated type name of the proxy contains the -> **\\`** <- character which causes SimpleInjector to see the type as a generic type. When SimpleInjector then tries to determine the number of generic arguments it parses the end of the generated type name which returns, for example, **2Proxy**. This causes a format exception to be thrown since the expectation is that only a number comes after the -> **\\`** <- . Here's a simple repro:\r\n\r\n``` c#\r\nusing NSubstitute;\r\nusing NUnit.Framework;\r\nusing SimpleInjector;\r\n\r\nnamespace SimpleInjectorRepro {\r\n\r\n    [TestFixture]\r\n    public class SimpleInjectorProxyTests {\r\n\r\n        [Test]\r\n        public void NonGeneric_Proxy_Type_Name_Causes_FormatException() {\r\n            var proxy = Substitute.For<IQueryHandler<MockQuery, MockResult>>();\r\n            var container = new Container();\r\n            container.Register(typeof(IQueryHandler<,>), proxy.GetType());\r\n            \r\n            Assert.Throws<ActivationException>(\r\n                () => container.GetInstance<IQueryHandler<MockQuery, MockResult>>());\r\n\r\n            //this name is parsed in src/SimpleInjector/Types.cs GetGenericArguments\r\n            //Which causes it to attempt to convert 2Proxy to int\r\n            Assert.AreEqual(\"IQueryHandler`2Proxy\", proxy.GetType().Name);\r\n\r\n            //Instead of trigger on `, just check IsGenericType\r\n            Assert.IsFalse(proxy.GetType().IsGenericType);\r\n        }\r\n    }\r\n\r\n    public interface IQueryHandler<TQuery, TResult> { }\r\n\r\n    public class MockQuery { }\r\n\r\n    public class MockResult { }\r\n}\r\n```\r\n\r\nTo correct this I'd propose to change \r\n\r\n**this:**\r\n\r\n``` c#\r\n if (!type.Name.Contains(\"`\"))\r\n{\r\n    return Enumerable.Empty<Type>();\r\n}\r\n```\r\n**To:**\r\n\r\n``` c#\r\n if (!type.IsGenericType)\r\n{\r\n    return Enumerable.Empty<Type>();\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/comments/306027463","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/426#issuecomment-306027463","issue_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/426","id":306027463,"user":{"login":"dotnetjunkie","id":1506621,"avatar_url":"https://avatars2.githubusercontent.com/u/1506621?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"created_at":"2017-06-04T08:54:34Z","updated_at":"2017-06-04T08:54:34Z","body":"As you will notice when you upgrade to v4.0.8, the bug in v4.0.7 prevented Simple Injector from throwing a correct exception describing the real problem with your configuration. With v4.0.8 you'll see the following exception:\r\n\r\n> SimpleInjector.ActivationException: The constructor of type IQueryHandler&#96;Proxy contains the parameter with name '' and type ICallRouter that is not registered. Please ensure ICallRouter is registered, or change the constructor of IQueryHandler&#96;Proxy.\r\n\r\nIn other words, Simple Injector is complaining that your type has a constructor that requires `ICallRouter` and that it is not registered. You should either add a registration for `ICallRouter` or change your registration to the following:\r\n\r\n``` c#\r\ncontainer.RegisterSingleton(proxy);\r\n```\r\n\r\n"}}
{"actor":{"display_login":"dotnetjunkie"}}