Build/Test Issues

Cannot run NUnit tests when datatypes in WPF DotNet Core assemblies are referenced

Started by Magnus on 3,415 views

I have a WPF dotnet Core 3.1 project and a separate test project, where I wish to be able to test ViewModels and Converters etc that reference WPF datatypes, such as the IValueConverter interface.

A minimal example is this dummy class in the WPF project:
 
    public class DummyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


with this simple test:

    [TestFixture]
    public class DummyConverterTests
    {
        [Test]
        public void ConverterTest()
        {
            var converter = new DummyConverter();

            Assert.That(converter, Is.Not.Null);
        }
    }


NCrunch seems to fail already during the exploration phase, marking the test with "Not runnable: Exception occured during exploration". When it anyway finds the test and tries to run it it gets marked as failed with the trace output:

System.IO.FileNotFoundException : Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
at MyWpfProject.Tests.Converters.DummyConverterTests.ConverterTest()


The test runs fine in Visual Studio 2019 Test Explorer. NCrunch can still run other tests in the test project that doesn't reference wpf.

Here is the project file for the test project:


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <IsPackable>false</IsPackable>
    <RootNamespace>MyWpfProject.Tests</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NSubstitute" Version="4.2.1" />
    <PackageReference Include="nunit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.16.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MySolution\MyWpfProject.csproj" />
  </ItemGroup>
</Project>



I have tried modifying the test project file like this:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <IsPackable>false</IsPackable>
    <RootNamespace>MyWpfProject.Tests</RootNamespace>
    <UseWpf>true</UseWpf>
  </PropertyGroup>
  ...


so the wpf assemblies are referenced, but it doesn't make any difference.
I haven't been able to figure out or find any other way to get the necessary wpf assemblies referenced in dotnet core.

Using NCrunch 4.2.0.7 in Visual Studio 2019 and dotnet core 3.1.

Thanks for any help,
Best regards Magnus

(I have the NCrunch license registered on my work mail but couldn't remember the password and tired of waiting for the reset password mail after 30 minutes...)

Edited

Hi thanks for taking the time to post this problem!

This is in an area of the framework that has been in flux the last couple of months and we've been working hard to fix all these issues.

We have a newer build that fixed a similar sounding problem. Would you mind giving that a try?

NCrunch_Console_4.3.0.6.msi
NCrunch_Console_4.3.0.6.zip
NCrunch_GridNodeServer_4.3.0.6.msi
NCrunch_GridNodeServer_4.3.0.6.zip
NCrunch_LicenseServer_4.3.0.6.zip
NCrunch_VS2008_4.3.0.6.msi
NCrunch_VS2010_4.3.0.6.msi
NCrunch_VS2010_4.3.0.6.zip
NCrunch_VS2012_4.3.0.6.msi
NCrunch_VS2012_4.3.0.6.zip
NCrunch_VS2013_4.3.0.6.msi
NCrunch_VS2013_4.3.0.6.zip
NCrunch_VS2015_4.3.0.6.msi
NCrunch_VS2015_4.3.0.6.msi.7z
NCrunch_VS2015_4.3.0.6.zip
NCrunch_VS2017_4.3.0.6.msi
NCrunch_VS2017_4.3.0.6.msi.7z
NCrunch_VS2017_4.3.0.6.zip
NCrunch_VS2019_4.3.0.6.msi
NCrunch_VS2019_4.3.0.6.msi.7z
NCrunch_VS2019_4.3.0.6.zip


I used the NCrunch_VS2019_4.3.0.6.msi and it solved the problem! Thanks!

(The reset password mail was in the spam folder by the way)
Some follow-up information on the 4.3.0.6 in VS2019. Nothing that is really stopping, but that I think you will want to fix.

The exploration phase still seems to have problems, and sometimes I get the "Not runnable: Exception occured during exploration" for the tests in the editor. I haven't been able to figure out a pattern to it.

Also, if I do the "Reload and rebuild selected component" for the test-project in your Tests-dialog, NCrunch always (so far) fails to build the project with the trace output:

An error occurred while analysing this project after it was built: NCrunch encountered an unexpected error occurred while building an environment to analyse an assembly: nCrunch.TaskRunner.Ipc.IpcConnectionClosedException: The connection has been closed
at nCrunch.Core.ProcessManagement.ExternalProcessManager.(EffectiveProcessorArchitecture , ProcessLoadParameters )
at nCrunch.Core.ProcessManagement.ExternalProcessManager.LoadExternalProcess(ProcessLoadParameters parameters, GridClientId client)
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.TestManagement.TestRunnerProcess.(Nullable`1 , FilePath , GridClientId , CustomVariable[] )
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.TestManagement.TestRunnerProcess.LoadTestRunnerProcessForProjectReturningProcessId(SnapshotComponent snapshotComponent, IList`1 componentsInProcess, TestFrameworkDescription[] testingFrameworks, Nullable`1 newProcessTag, FilePath solutionFilePath, GridClientId client, CustomVariable[] customEnvironmentVariables)
at nCrunch.Core.Processing.AnalysisTaskLogic.DoProcessTaskAndReturnSuccessFlag()

Restarting the NCrunch engine gets it running again.
Hi Magnus,

Would you mind trying the build below? I did some hardening in generating the dependency data. I'm not sure this will solve your specific issue, but it might be worth a try.

NCrunch_Console_4.3.0.7.msi
NCrunch_Console_4.3.0.7.zip
NCrunch_GridNodeServer_4.3.0.7.msi
NCrunch_GridNodeServer_4.3.0.7.zip
NCrunch_LicenseServer_4.3.0.7.zip
NCrunch_VS2008_4.3.0.7.msi
NCrunch_VS2010_4.3.0.7.msi
NCrunch_VS2010_4.3.0.7.zip
NCrunch_VS2012_4.3.0.7.msi
NCrunch_VS2012_4.3.0.7.zip
NCrunch_VS2013_4.3.0.7.msi
NCrunch_VS2013_4.3.0.7.zip
NCrunch_VS2015_4.3.0.7.msi
NCrunch_VS2015_4.3.0.7.msi.7z
NCrunch_VS2015_4.3.0.7.zip
NCrunch_VS2017_4.3.0.7.msi
NCrunch_VS2017_4.3.0.7.msi.7z
NCrunch_VS2017_4.3.0.7.zip
NCrunch_VS2019_4.3.0.7.msi
NCrunch_VS2019_4.3.0.7.msi.7z
NCrunch_VS2019_4.3.0.7.zip
Tried it, same behavior.
Magnus wrote:Tried it, same behavior.


Sorry to hear that. Would you be able to submit an NCrunch bug report right after this has happened to you? The report may yield some more information about why the process is suddenly disappearing.

Also, just to confirm - you mentioned that there are situations where it does actually run correctly. Is this still the case? If it's intermittent, have you managed to find any pattern around the intermittency?
I just submitted a bug report, with this trace output in the test window:

An error occurred while analysing this project after it was built: NCrunch encountered an unexpected error occurred while building an environment to analyse an assembly: nCrunch.TaskRunner.Ipc.IpcConnectionClosedException: The connection has been closed
at nCrunch.Core.ProcessManagement.ExternalProcessManager.(EffectiveProcessorArchitecture , ProcessLoadParameters )
at nCrunch.Core.ProcessManagement.ExternalProcessManager.LoadExternalProcess(ProcessLoadParameters parameters, GridClientId client)
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.TestManagement.TestRunnerProcess.(Nullable`1 , FilePath , GridClientId , CustomVariable[] )
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.TestManagement.TestRunnerProcess.LoadTestRunnerProcessForProjectReturningProcessId(SnapshotComponent snapshotComponent, IList`1 componentsInProcess, TestFrameworkDescription[] testingFrameworks, Nullable`1 newProcessTag, FilePath solutionFilePath, GridClientId client, CustomVariable[] customEnvironmentVariables)
at nCrunch.Core.Processing.AnalysisTaskLogic.DoProcessTaskAndReturnSuccessFlag()
Thanks for sending through the report.

It looks like the process isn't giving us any error information in the NCrunch logs. This means that something is going wrong inside the platform itself.

Can you see anything inside the windows event viewer related to the process that's blowing up?

Have you managed to establish any pattern around when this happens? Is it intemittent?
There is nothing that I can see in the Windows Event Viewer.
I can repeat the build problem with so far 100% certainty by chosing "Reload and rebuild selected component" for the test project in the the NCrunch Tests dialog. I then have to cllick "Restart the ncrunch engine" to get it running again.
The problem often show up spontanously when I do significant changes to the workspace, e.g., by switching branches in git.
Are you able to build a sample solution that can produce this issue? Are you able to produce it by running your tests one at a time?
The new version 4.3.0.13 solved all the problems I had, thanks! (orginal poster here, on my work-account)
'

Post a reply

Log in to reply.