nunit: Ncrunch: System.Xml.XmlException: Root element is missing. when adding nUnit 3.7.0
Hi,
When creating a new solution (wep api) with a unit test project I get the following error when I add nUnit 3.7.0 to the unit test project.
An error occurred while analysing this project after it was built: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Xml.XmlException: Root element is missing. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at NUnit.Framework.Interfaces.TNode.FromXml(String xmlText) at NUnit.Framework.Internal.TestFilter.FromXml(String xmlText) at NUnit.Framework.Api.FrameworkController.ExploreTests(ICallbackEventHandler handler, String filter) at NUnit.Framework.Api.FrameworkController.ExploreTestsAction..ctor(FrameworkController controller, String filter, Object handler) --- End of inner exception stack trace ---
To clarify The project will run properly in Visual Studio. The error is shown in the NCrunch test runner and therefor I cannot start TDDing properly. The problem is resolved when reverting to nUnit version 3.6.1. In this new solution I also installed specFlow and I have resharper installed in Visual Studio.
I do not know if this is an NCrunch, nUnit, VS issue. Because the problem is fixed when going back to an older version of nUnit i suspect it to be here hence this post.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (10 by maintainers)
The 3.7.1 hotfix is out. I also updated the docs to state that a null or empty string is also accepted for an empty filter as of NUnit 3.7.1, but
<filter/>should be used for backwards compatibility.As a shallow fix, we could transform a null or empty string to an empty filter. Even though the behaviour isn’t specified AFAIK, I think we should handle it. The question is, is this serious enough to warrant a hotfix? We may get the same error from other runners since filters weren’t previously supported.
Related, @remcomulder is there any way that NCrunch could do some integration testing with our dev builds on MyGet so that we can catch issues like this prior to release?
Thanks for pinging me in on this one. NCrunch is passing string.Empty into the filter parameter here. I can’t remember the reasoning behind this. It may have been that I tried to pass (null), and that didn’t work, so string.Empty seemed like the next best thing and NUnit has always accepted this. I don’t remember it ever being specified that an empty filter should be passed here in the event of no filter.
Regardless, this is easy to fix in NCrunch, but it’s still a bit a problem, because it completely breaks the forwards compatibility for using NUnit with older versions of NCrunch. I would state my preference being that perhaps NUnit should avoid exploding when an empty string is passed into the filter. In this way, we can avoid breaking things for people when they perform a Nuget update.
@CharliePoole Thoughts?
@BrianLanghoor beat me to the punch! I was just about to announce that NCrunch v3.9 is out now with a fix for this issue.
@rprouse Bit of history: We used to transform null into TestFilter.Empty. I stopped that with 3.0 because it seemed to me to encourage sloppy programming (on our part).
I wondered if this had anything to do with rushing to get the fix into the release, but that’s not the case, since this fix went into master a month ago. If ncrunch were running regular builds against our dev packages, then this would have been caught. That’s what I recommended when we did the last hotfix for @remcomulder.
@remcomulder I see this as another unfortunate occurrence, one which we would have avoided if we knew it was a problem. I would have favored adding special code to allow your older versions to keep working… i.e. translate the empty string to “<filter />” … i.e. would have if you had told us about the problem before we released. The dev build that contained this change was on our feed on April 24.
Now however, we are released, which makes things more difficult. The decision is up to @rprouse but frankly, I think this is a problem that we didn’t have to have. If you had been running builds against our dev releases, as I asked the last time something like this happened, then you would have told us about the problem and we would have put in code - even ugly code if necessary - to keep you working. My vote on this occasion is to put in the fix but not release a hotfix until/unless we see there are other fires to put out.
This will be due to the new functionality to use the filter passed to Explore. It looks like NCrunch is passing a non-xml string in, @remcomulder - can you shed any light? For context, prior to v3.7, the
string filterpassed intoExporeTests()was unused, however it’s now being parsed and read. It should be an xml<filter>element I believe - and an empty<filter />if unused.I’d guess this was caused by the change in NUnit 3.7, but will need fixing in NCrunch. Will leave this issue open until confirmed.