{"action":"created","issue":{"url":"https://api.github.com/repos/xunit/xunit/issues/805","repository_url":"https://api.github.com/repos/xunit/xunit","labels_url":"https://api.github.com/repos/xunit/xunit/issues/805/labels{/name}","comments_url":"https://api.github.com/repos/xunit/xunit/issues/805/comments","events_url":"https://api.github.com/repos/xunit/xunit/issues/805/events","html_url":"https://github.com/xunit/xunit/issues/805","id":142095161,"number":805,"title":"Cannot use a Theory accepting a generic array","user":{"login":"mellinoe","id":8918977,"avatar_url":"https://avatars.githubusercontent.com/u/8918977?v=3","gravatar_id":"","url":"https://api.github.com/users/mellinoe","html_url":"https://github.com/mellinoe","followers_url":"https://api.github.com/users/mellinoe/followers","following_url":"https://api.github.com/users/mellinoe/following{/other_user}","gists_url":"https://api.github.com/users/mellinoe/gists{/gist_id}","starred_url":"https://api.github.com/users/mellinoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mellinoe/subscriptions","organizations_url":"https://api.github.com/users/mellinoe/orgs","repos_url":"https://api.github.com/users/mellinoe/repos","events_url":"https://api.github.com/users/mellinoe/events{/privacy}","received_events_url":"https://api.github.com/users/mellinoe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-03-19T19:41:00Z","updated_at":"2016-10-23T21:25:05Z","closed_at":"2016-10-23T21:25:05Z","body":"Consider this test case:\r\n````CSharp\r\n[Theory]\r\n[InlineData(new int[] { 1, 2, 3 })]\r\npublic static void Test<T>(T[] array)\r\n{\r\n    foreach (var i in array)\r\n    {\r\n        Console.WriteLine(i);\r\n    }\r\n}\r\n````\r\nAn exception occurs when the test case is run. Here is the stack trace:\r\n````\r\nClassLibrary1.Class1.Test<Object>(array: [1, 2, 3]) [FAIL]\r\n      System.ArgumentException : Object of type 'System.Int32[]' cannot be converted to type 'System.Object[]'.\r\n      Stack Trace:\r\n           at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)\r\n           at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)\r\n           at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)\r\n           at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n           at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n        --- End of stack trace from previous location where exception was thrown ---\r\n           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n        --- End of stack trace from previous location where exception was thrown ---\r\n           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n````\r\n\r\nBased on the above, it seems that the wrong generic method is being created for the test method, i.e. `Test<Object>()` rather than `Test<Int32>()`.\r\n\r\nAnother thing to note: if a generic constrant is applied to the test method, i.e.:\r\n\r\n````\r\npublic static void Test<T>(T[] array) where T : struct\r\n````\r\n\r\nthis also fails, with a different exception: \r\n\r\n````\r\nClassLibrary1.Class1.Test [FAIL]\r\n      System.ArgumentException : GenericArguments[0], 'System.Object', on 'Void Test[T](T[])' violates the constraint of type 'T'.\r\n      ---- System.Security.VerificationException : Method ClassLibrary1.Class1.Test: type argument 'System.Object' violates the constraint of type parameter 'T'.\r\n      Stack Trace:\r\n           at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)\r\n           at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)\r\n        ----- Inner Stack Trace -----\r\n           at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)\r\n           at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation\r\n````\r\nI believe this exception occurs when the test case is being generated. Presumably calling `MakeGenericMethod` with T=System.Object fails because it does not meet the constraints.\r\n\r\nAs another side note, the test case with the generic constraint cause the VS test runner to \"run continuously\" trying to discover the tests and seems to get stuck in a loop."},"comment":{"url":"https://api.github.com/repos/xunit/xunit/issues/comments/255615604","html_url":"https://github.com/xunit/xunit/issues/805#issuecomment-255615604","issue_url":"https://api.github.com/repos/xunit/xunit/issues/805","id":255615604,"user":{"login":"bradwilson","id":16944,"avatar_url":"https://avatars.githubusercontent.com/u/16944?v=3","gravatar_id":"","url":"https://api.github.com/users/bradwilson","html_url":"https://github.com/bradwilson","followers_url":"https://api.github.com/users/bradwilson/followers","following_url":"https://api.github.com/users/bradwilson/following{/other_user}","gists_url":"https://api.github.com/users/bradwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/bradwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradwilson/subscriptions","organizations_url":"https://api.github.com/users/bradwilson/orgs","repos_url":"https://api.github.com/users/bradwilson/repos","events_url":"https://api.github.com/users/bradwilson/events{/privacy}","received_events_url":"https://api.github.com/users/bradwilson/received_events","type":"User","site_admin":false},"created_at":"2016-10-23T21:25:05Z","updated_at":"2016-10-23T21:25:05Z","body":"Fixed by #965"}}
{"actor":{"display_login":"bradwilson"}}