approvals/ApprovalTests.Net

System.TypeInitializationException : The type initializer for 'EmptyFiles' threw an exception.

Closed this issue ยท 4 comments

It looks like a regression in ApprovalTests v4.5.1, the same code works as expected in v4.5.0

[assembly: UseReporter(typeof(P4MergeReporter))]

        [Fact]
        public void VerifyAttributes()
        {
            Dictionary<string, Attribute[]> dic = TypeMembersDecoratior.EnumerateAttributes(typeof(ListViewItem).Assembly);

            Approvals.VerifyAll(dic);
        }
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:08.53]     System.Windows.Forms.Tests.Serialization.TypeMembersAttributeDecorationTests.VerifyAttributes [FAIL]
  X System.Windows.Forms.Tests.Serialization.TypeMembersAttributeDecorationTests.VerifyAttributes [118ms]
  Error Message:
   System.TypeInitializationException : The type initializer for 'EmptyFiles' threw an exception.
---- System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Development\winforms\artifacts\bin\System.Windows.Forms.Tests\Debug\netcoreapp5.0\EmptyFiles'.
  Stack Trace:
     at EmptyFiles.TryGetPathFor(String extension, String& path) in C:\projects\emptyfiles\src\EmptyFiles\EmptyFiles.cs:line 108
   at ApprovalTests.Reporters.GenericDiffReporter.EnsureFileExists(String approved)
   at ApprovalTests.Reporters.GenericDiffReporter.Report(String approved, String received)
   at ApprovalTests.Reporters.FirstWorkingReporter.Report(String approved, String received)
   at ApprovalTests.Approvers.FileApprover.ReportFailure(IApprovalFailureReporter reporter)
   at ApprovalTests.Core.Approver.Verify(IApprovalApprover approver, IApprovalFailureReporter reporter)
   at ApprovalTests.Approvals.Verify(IApprovalApprover approver, IApprovalFailureReporter reporter)
   at ApprovalTests.Approvals.Verify(IApprovalWriter writer, IApprovalNamer namer, IApprovalFailureReporter reporter)
   at ApprovalTests.Approvals.Verify(IApprovalWriter writer)
   at ApprovalTests.Approvals.VerifyWithExtension(String text, String fileExtensionWithDot, Func`2 scrubber)
   at ApprovalTests.Approvals.Verify(String text, Func`2 scrubber)
   at ApprovalTests.Approvals.VerifyAll[T](IEnumerable`1 enumerable, Func`2 formatter)
   at ApprovalTests.Approvals.VerifyAll[K,V](IDictionary`2 dictionary)
   at System.Windows.Forms.Tests.Serialization.TypeMembersAttributeDecorationTests.VerifyAttributes() in C:\Development\winforms\src\System.Windows.Forms\tests\UnitTests\SerializableAttributeTests.cs:line 47
----- Inner Stack Trace -----
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1.Init()
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
   at EmptyFiles..cctor() in C:\projects\emptyfiles\src\EmptyFiles\EmptyFiles.cs:line 19


Test Run Failed.
jawn commented

Duplicate of #329, which also describes a workaround

Thank you. Though it is hard to tell that it is a dup of an issue with an unclear subject and an empty description.

my bad, I've submitted too quick and added the description in the following comment! I've retrofitted it.

This is now deployed. NuGet may take some time to make it available for download.