0

Since some days all my C# unit tests in Visual Studio running on my local machine are raising following TypeInitializationException when reaching the first Shouldly statement:

The type initializer for 'Shouldly.ShouldlyConfiguration' threw an exception

with the inner exception

Illegal characters in path

And a stack trace:

at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Shouldly.Configuration.DiffTool.<>c__DisplayClass10_0.<GetFullPath>b__2(String path)
at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Shouldly.Configuration.DiffTool.GetFullPath(String fileName)
at Shouldly.Configuration.DiffTool.Discover(String path)
at Shouldly.Configuration.DiffTool..ctor(String name, String path, ArgumentGenerator argGenerator)
at Shouldly.Configuration.KnownDiffTools..ctor()
at Shouldly.Configuration.KnownDiffTools..cctor()

There is a similar issue on https://github.com/shouldly/shouldly/issues/422 but my PATH Environment is correct.

I get the same error for any Unit Test Project Independent of the path.

Even for the simplest test as

  [TestClass]
  public class UnitTest2
  {
    [TestMethod]
    public void TestMethod1()
    {
      int i = 1;
      i.ShouldBe(1);
    }
  }

On other machines I cannot reproduce the issue for the same tests.

StefanG
  • 1,234
  • 2
  • 22
  • 46

1 Answers1

0

Based on that stack trace, the path to your diff tool is not a valid path.

Shouldly retrieves all paths from the PATH variable and tries to "guess" the path to one of the pre-defined diff tools.

When one of the paths is invalid, this exception is raised. A solution is currently implmented. See https://github.com/shouldly/shouldly/pull/423

StefanG
  • 1,234
  • 2
  • 22
  • 46
NP3
  • 1,114
  • 1
  • 8
  • 15
  • I think that the path shouldly _uses_ to search, is not valid. But what parameter does it take? The path to Shouldly on my machine is valid. See https://github.com/shouldly/shouldly/blob/master/src/Shouldly/Configuration/DiffTool.cs – StefanG Apr 18 '17 at 21:04