Build/Test Issues

Could not load file or assembly 'PresentationCore, Version=4.0.0.0,...

Started by Dirk Maegh on 8,811 views

Hi I got the following problem, and it seems related to another forum post, but I didn't want to hijack that post, because I don't know it's exactly the same issue.

Exception is
System.IO.FileNotFoundException: Could not load file or assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

It is triggered as soon as I want to instantiate a viewmodel, that manages some properties of type Visibility.
Another failed test in the same solution is when I try to load some resources to verify they are correctly loaded.

It's about a unittest/integration test that references a WPF desktop project, and needs some presentationcore to instantiate a viewmodel (to support Visibility).
The unittest could not load PresentationCore as it is not directly referenced.

I have tried to modify the unittest project to UseWPF and Sdk="Microsoft.NET.Sdk.WindowsDesktop". Thought that would help, to no avail though.

I have a small custom solution for you to check out.
I just don't know where to post it. Can I send it to you directly ?

Thx,
Dirk
Hi Dirk,

Thanks for sharing this issue.

We've been on a bit of a roller coaster with these sorts of issues over the last couple of months.

Would you be interested in trying the build below to see if this solves the issue for you?

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

If the above build doesn't fix it, you're most welcome to ZIP up your test solution and submit it through the contact form. We'll then take a deep look at it and figure out what's going wrong with the runtime resolution.
I have installed this build, but the tests still fail.

I get a different error however.
NCrunch encountered an error while trying to construct an environment to execute this test: 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.TestExecutionTaskLogic.DoProcessTaskAndReturnSuccessFlag()

Maybe I am doing something wrong ?

Sample solution sent through the contact form.
Thanks for sending through the sample. We'll take a look at this and will get back to you as soon as we have more information.
Hi,

Would you mind trying the build below?

NCrunch_Console_4.3.0.11.msi
NCrunch_Console_4.3.0.11.zip
NCrunch_GridNodeServer_4.3.0.11.msi
NCrunch_GridNodeServer_4.3.0.11.zip
NCrunch_LicenseServer_4.3.0.11.zip
NCrunch_VS2008_4.3.0.11.msi
NCrunch_VS2010_4.3.0.11.msi
NCrunch_VS2010_4.3.0.11.zip
NCrunch_VS2012_4.3.0.11.msi
NCrunch_VS2012_4.3.0.11.zip
NCrunch_VS2013_4.3.0.11.msi
NCrunch_VS2013_4.3.0.11.zip
NCrunch_VS2015_4.3.0.11.msi
NCrunch_VS2015_4.3.0.11.msi.7z
NCrunch_VS2015_4.3.0.11.zip
NCrunch_VS2017_4.3.0.11.msi
NCrunch_VS2017_4.3.0.11.msi.7z
NCrunch_VS2017_4.3.0.11.zip
NCrunch_VS2019_4.3.0.11.msi
NCrunch_VS2019_4.3.0.11.msi.7z
NCrunch_VS2019_4.3.0.11.zip
Hi, just tested with the new suggested version.

Of the two tests in the sample solution, one ran without problems now - 50% fixed ;)
The other test showed the following exception

System.UriFormatException: Invalid URI: Invalid port specified.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at ...ResourceManager.<>c.<.ctor>b__3_0() in C:\...\ncrunch\...\ResourceManager.cs:line 9 (line abbreviated)
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
...

I get the same error when I just try to instantiate a Uri directly in the test method with the pack syntax like
new Uri(@"pack://application:,,,/Resources/notebook.png", UriKind.Absolute);

Thanks for looking into this.
Hi,

Thanks for testing this so quickly. Glad 50% works.

I had a look at the failing test to see what the VS runner does in that case. That seems to crash on the whole test set, with a stack overflow exception. The same happens with dotnet test. Does that happen for you too? If it does could you try to generate an example that works in the VS runner, but not in NCrunch?

If it does pass in the VS runner, could you please post what version of VS you are using?
Hi, I can confirm that the following test fails in VS runner as well. (did not check dotnet test)

[TestMethod]
public void TestUri()
{
new Uri(@"pack://application:,,,/Resources/notebook.png", UriKind.Absolute);
}

with the following exception:
System.UriFormatException: Invalid URI: Invalid port specified.

It is odd, because I run this code from a WPF application, and it is used to get a BitmapImage from this uri. (new BitmapImage(new Uri(...))
And in the WPF application, the bitmap is shown. (no error)

The test in the unittest project fails however, and it seems unrelated to ncrunch because the vs runner has the same "problem".
Thanks for your excellent work !
I have been trying to fix this.

Debugging through .Net code (not just my code) seems to run fine - odd again.

Then I stumbled on this thread:
https://stackoverflow.com/questions/6005398/uriformatexception-invalid-uri-invalid-port-specified

All I had to do was to add the following code to fix things with the "Invalid port specified" exception.
[TestInitialize]
public void Initialize()
{
if (!UriParser.IsKnownScheme("pack"))
new System.Windows.Application();
}


Then finally I got the "Cannot locate resource 'resources/notebook.png'" - the error I was going for.
And I then could fix it by correcting the uri itself - I had to include the assembly name where the resource was registered.
as such:
@"pack://application:,,,/MyAssemblyName;component/Resources/notebook.png"

All is well that ends well.
Thanks again for your investigation !

(issue closed)

Post a reply

Log in to reply.