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

InvalidOperationException thrown in string.Join running MemberData tests #987

Closed
hughbe opened this issue Sep 26, 2016 · 7 comments
Closed

Comments

@hughbe
Copy link
Contributor

hughbe commented Sep 26, 2016

The following throws an InvalidOperationException when running tests, with the stack trace attached
stacktrace

using System.Json;
public static IEnumerable<object[]> TestData()
{
    yield return new object[] { new JsonValue[] { new JsonPrimitive(true) } };
}

[Theory]
[MemberData(nameof(TestData))]
public void Test(JsonValue[] items)
{
    JsonArray array = new JsonArray(items);
}

This is a bug in xunit I think, as the error doesn't seem to be coming from my code - there is no mention of string.Join anywhere.
The reason why an InvalidOperationException is thrown is that JsonValue throws this exception when GetEnumerator is called.

/cc @stephentoub FYI

@hughbe hughbe changed the title MemberData with a member InvalidOperationException thrown in string.Join running MemberData tests Sep 26, 2016
@bradwilson
Copy link
Member

Are you sure about that? The very top of the stack trace is your code (JsonValue.cs).

@hughbe
Copy link
Contributor Author

hughbe commented Sep 26, 2016

Right, the exception is thrown from the GetEnumerator method in JsonValue.cs.

But my issue is that this code is being called from xunit, specifically some kind of string.Join call

@bradwilson
Copy link
Member

Can you point to the implementation of JsonValue?

@hughbe
Copy link
Contributor Author

hughbe commented Sep 26, 2016

@bradwilson
Copy link
Member

Curious: Why are you implementing IEnumerable, only to throw InvalidOperationException?

@stephentoub
Copy link
Contributor

But my issue is that this code is being called from xunit, specifically some kind of string.Join call

Presumably this is by design, and xunit is attempting to serialize any IEnumerable as part of the name of a theory? It might be nice if it caught exceptions from enumeration and ignored them, assuming this is part of name generation or something similarly non-fatal. That said, this doesn't seem like a bug to me.

Curious: Why are you implementing IEnumerable, only to throw InvalidOperationException?

I ported this code, and I'm wondering the same thing ;) I need to go dig up an old copy of the Silverlight library to see what it was doing here. This is a straight port of Mono's implementation, which we brought to corefx for compat with code that's using it there.

@hughbe
Copy link
Contributor Author

hughbe commented Sep 26, 2016

It's probs not a bug, I was incorrect in identifying it as such. I just wanted to identify this as a limitation. I agree that catching the IOE would be nice but not essential. As a non-microsoftie I have no idea why anyone would implement JsonValue like that!

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

No branches or pull requests

3 participants