Daily Usage Issues

Implicit Project Dependencies

Started by spolonski on 2,495 views

Hi Remco,

If I set in the Ncrunch settings that the project should use Implicit Project Dependencies, an error occurs during the build.

System.InvalidCastException: Unable to cast object of type 'nCrunch.Client.Settings.ImplicitProjectDependencies' to type 'nCrunch.Client.Settings.CopiedProjectDependencies'.
   at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.()
   at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(EffectiveProcessorArchitecture , String )
   at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, IDEVersion ideVersion, BuildEngineId buildEngineId, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFrameworkForMsbuild, String visibleTargetFramework)

NCrunch Version 5.9.0.1
Thanks for sharing this issue. Could you copy/paste the .v3.ncrunchproject file containing this configuration? I can't seem to recreate this with a code sample when I build this setting in the UI.
Sure. Here is it.

<ProjectConfiguration>
  <Settings>
    <ImplicitProjectDependencyPathsRelativeToSolutionDirectory>
      <Value>MyIdClient\MyIdClient.csproj</Value>
    </ImplicitProjectDependencyPathsRelativeToSolutionDirectory>
  </Settings>
</ProjectConfiguration>



TestProject is a full framework and a MyIdClient is a core project.
Oddly this seems to be ok on my end.

Is there any chance you can whittle this down to a sample solution you can share with me? You can submit small code samples in ZIP form through the NCrunch contact form.
I was trying to submit a demo today, but I got an error every time after I clicked on the submit button. I am not sure if a file was sent or not.

The behavior in a small demo is slightly different. I don't get an exception during the NCrunch build anymore, but the test case is not discovered anymore.

When I remove the "Implicit Project Dependencies" setting from a test project, the test is discovered correctly.
I have uploaded a demo under https://drive.google.com/file/d/1afVQkeuZ6uRU9I2h04zOLLR6HuHQ76Sg/view?usp=drive_link
I apologise for the time it's taken me to get back to you on this. I've reproduced the issue as you've described it and we're working to get a fixed build for you. Unfortunately in this case the problem needs to be fixed in NCrunch itself (there is no direct workaround), so a new build is necessary.
Would you be interested in trying the build below to see if this solves the problem for you?

NCrunch_Console_5.10.0.2.msi
NCrunch_Console_5.10.0.2.zip
NCrunch_GridNodeServer_5.10.0.2.msi
NCrunch_GridNodeServer_5.10.0.2.zip
NCrunch_LicenseServer_5.10.0.2.zip
NCrunch_Rider_5.10.0.2.7z
NCrunch_Rider_5.10.0.2.zip
NCrunch_VS2010_5.10.0.2.msi
NCrunch_VS2010_5.10.0.2.zip
NCrunch_VS2012_5.10.0.2.msi
NCrunch_VS2012_5.10.0.2.zip
NCrunch_VS2013_5.10.0.2.msi
NCrunch_VS2013_5.10.0.2.zip
NCrunch_VS2015_5.10.0.2.msi
NCrunch_VS2015_5.10.0.2.msi.7z
NCrunch_VS2015_5.10.0.2.zip
NCrunch_VS2017_5.10.0.2.msi
NCrunch_VS2017_5.10.0.2.msi.7z
NCrunch_VS2017_5.10.0.2.zip
NCrunch_VS2019_5.10.0.2.msi
NCrunch_VS2019_5.10.0.2.msi.7z
NCrunch_VS2019_5.10.0.2.zip
NCrunch_VS2022_5.10.0.2.msi
NCrunch_VS2022_5.10.0.2.msi.7z
NCrunch_VS2022_5.10.0.2.zip
Thanks. Test discovery works as expected, but I have the next problem with a test case. I can't run an exe from a "ImplcitlyReferencedAssemlyLocation".
I am getting an exception:


C:\Users\spolonski\AppData\Local\NCrunch\3268\5\XXXIdClient\bin\x86\Debug\net8.0-windows\XXXIdClient.exe

Error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'nCrunch.TestRuntime.DotNetCore, Version=5.10.0.2, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea'. The system cannot find the file specified.
File name: 'nCrunch.TestRuntime.DotNetCore, Version=5.10.0.2, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea'
   at XXXId.Client.App..ctor()
   at XXXId.Client.App.Main()


Hmm. I don't referencing a nCrunch.TestRuntime.DotNetCore in XXXIdClient project.

Is it possible to start an exe from a Ncrunch Test Case?
Yes, this is possible. But it can be somewhat painful to get set up with.

The first complication is, as you've discovered, assemblies instrumented by NCrunch have a reference to nCrunch.TestRuntime. You'll need to copy this assembly programmatically into the same directory as the .EXE so that it can find them at run time. I would suggest running through the assemblies loaded into the test's application domain and finding the assembly path from there, since it needs to be loaded for the NCrunch test domain to function.

The second complication is that the EXE is likely to be alone in its NCrunch workspace without its dependencies adjacent to it. There are two ways you can handle this, either by copying the dependencies into the same directory (using implicit dependencies, the methods in NCrunch.Framework.NCrunchEnvironment, or running through the application domain in your test environment) .. or you can just turn on the copy referenced assemblies to workspace setting for the .EXE so that its dependencies are present.

A third complication is that managing the lifetime of the EXE can be tricky, especially if the test doesn't tear down properly .. as this can leave an orphaned EXE hanging around. There are ways to solve this problem. The best approach usually depends on how you're using the process.

The good news is that both code coverage tracking and RDI should work for the EXE's process, which is VERY powerful for tracking problems and understanding code. We use this approach ourselves in NCrunch's tests (many of which are multiprocess in the same way as yours). It saves us a lot of time.

Edited

Post a reply

Log in to reply.