Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

3 Pages123>
Unable to run tests with .NET Core 2.0 referencing .NET Standard 2.0
bartj
#1 Posted : Monday, August 14, 2017 8:59:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2013(UTC)
Posts: 26
Location: New Zealand

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
I have a simple solution with a .NET Standard 2.0 (RTM) project and a .NET Core 2.0 (RTM) project that depends on the .NET Standard project. The solution builds fine in Visual Studio, but NCrunch simply shows a blue question-mark next to the test project. It also fails to build the .NET Standard 2.0 project, but that isn't a problem for me because it doesn't contain tests.

When I remove the dependency from the test project to the .NET Standard project and comment out the test body, the project builds in NCrunch and the tests run.

Is .NET Standard 2.0 / .NET Core 2.0 compatibility coming soon?

UPDATE: this problem also occurs when referencing a .NET Standard 2.0 project from a .NET Framework 4.7 project. I'm running NCrunch 3.10.0.20.
Remco
#2 Posted : Monday, August 14, 2017 11:27:22 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this problem.

Handling of .NET Core/Standard 2.0 is hit and miss at the moment. The reason for this is because every time NCrunch gets updated to handle this framework, MS push out a new release and it all gets broken again. Although .NET Core 2.0 is now announced as 'RTM' by Microsoft, NCrunch is still totally reliant on the MS tool stack that supports it, and this tool stack isn't expected to be released until mid September.

I appreciate you reporting a use case here that doesn't work correctly, I'll make sure I have a chance to review it before the next NCrunch update.
DavidArnoDandG
#3 Posted : Tuesday, August 15, 2017 3:38:12 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/16/2017(UTC)
Posts: 6
Location: United Kingdom

Thanks: 1 times
Was thanked: 4 time(s) in 2 post(s)
If it helps, I have a solution at https://github.com/David...o/Standard.Abstractions that has such problems (though may not be directly related to the OP's issue).

Using VS2017 Update 3, netstandard 2.0 and .NET Core 2.0 RTW's (all updated today), with NCrunch v3.10, NCrunch gives the following error when it attempts to build:

Quote:
System.ArgumentNullException: Value cannot be null.
Parameter name: type
at _Mono.Cecil.ModuleDefinition.Import(TypeReference type)
at nCrunch.Compiler.StaticManipulation.StaticInstrumentationImportMethodSet..ctor(CustomCecilAssemblyResolver resolver, ModuleDefinition module)
at nCrunch.Core.PlatformTypes.DotNetCorePlatformType.GetInstrumentationMethodsForFramework(CustomCecilAssemblyResolver resolver, AssemblyDefinition assembly)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.Instrument(ComponentSourceLineMap sourceLineMap, IDictionary`2 instrumentationDirectivesByCodeFileId, IDictionary`2 codeFileIDsByFilePath, Boolean proxyProcessIsActive, Int32 componentId, IInstrumentationFilter[] instrumentationFilters, IBuildPlatformType platformType, PerfTracker perfTracker)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters )


Apologies though if this is an unrelated issue.
3 users thanked DavidArnoDandG for this useful post.
Remco on 8/15/2017(UTC), osoykan on 8/15/2017(UTC), sextondjc on 8/15/2017(UTC)
osoykan
#4 Posted : Tuesday, August 15, 2017 8:53:24 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/15/2017(UTC)
Posts: 4
Location: Turkey

Thanks: 2 times
Yes, I have the same error, too.

DavidArnoDandG;10986 wrote:
If it helps, I have a solution at https://github.com/David...o/Standard.Abstractions that has such problems (though may not be directly related to the OP's issue).

Using VS2017 Update 3, netstandard 2.0 and .NET Core 2.0 RTW's (all updated today), with NCrunch v3.10, NCrunch gives the following error when it attempts to build:

Quote:
System.ArgumentNullException: Value cannot be null.
Parameter name: type
at _Mono.Cecil.ModuleDefinition.Import(TypeReference type)
at nCrunch.Compiler.StaticManipulation.StaticInstrumentationImportMethodSet..ctor(CustomCecilAssemblyResolver resolver, ModuleDefinition module)
at nCrunch.Core.PlatformTypes.DotNetCorePlatformType.GetInstrumentationMethodsForFramework(CustomCecilAssemblyResolver resolver, AssemblyDefinition assembly)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.Instrument(ComponentSourceLineMap sourceLineMap, IDictionary`2 instrumentationDirectivesByCodeFileId, IDictionary`2 codeFileIDsByFilePath, Boolean proxyProcessIsActive, Int32 componentId, IInstrumentationFilter[] instrumentationFilters, IBuildPlatformType platformType, PerfTracker perfTracker)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters )


Apologies though if this is an unrelated issue.

sextondjc
#5 Posted : Tuesday, August 15, 2017 9:44:01 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Same here.
Remco
#6 Posted : Wednesday, August 16, 2017 6:37:08 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
2 users thanked Remco for this useful post.
yanglee on 8/16/2017(UTC), EsbjornRedmo on 8/17/2017(UTC)
DavidArnoDandG
#7 Posted : Wednesday, August 16, 2017 9:03:09 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/16/2017(UTC)
Posts: 6
Location: United Kingdom

Thanks: 1 times
Was thanked: 4 time(s) in 2 post(s)
Hi Remco,

I have installed http://downloads.ncrunch...nch_VS2017_3.11.0.4.msi and the net standard project now compiles just fine. Thanks.

However, the tests now fail with the error:
Quote:
System.BadImageFormatException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
File name: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\ref\netstandard.dll' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
File name: 'file:///C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.0\build\netstandard2.0\ref\netstandard.dll' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at nCrunch.Common.CustomAssemblyResolver.ResolveAssembly(ParsedAssemblyName parsedAssemblyName)
at nCrunch.Common.CustomAssemblyResolver.(Object , ResolveEventArgs )
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)


at Standard.Abstractions.Tests.UnitTest1.Directory_CanBeCreatedAndCorrectlyShowsItExists()


I've tried targeting netcoreapp2.0, net461 and net47. I've tried adding a reference to NETStandard.Library 2.0.0 nuget package. None of these makes a difference though.

Am I doing something wrong. or is there still an issue?

Remco
#8 Posted : Wednesday, August 16, 2017 12:32:28 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi David,

If I were to guess, this looks to be the result of confusion in the test environment between the netstandard compile-time assembly and run-time assembly. Probably this is the result of another late-game change to the .NET Core toolset.

Unfortunately I'm not sure how to produce this. It doesn't look to be specific to a default netstandard project, so I guess there must be another variable here. Is there any chance you could share with me a self-contained code sample that I can use to reproduce the problem? You're welcome to submit any code through the contact form.
DavidArnoDandG
#9 Posted : Wednesday, August 16, 2017 2:50:52 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/16/2017(UTC)
Posts: 6
Location: United Kingdom

Thanks: 1 times
Was thanked: 4 time(s) in 2 post(s)
Hi Remco,

The code that exhibits this behaviour can be git pulled from https://github.com/David.../Standard.Abstractions. But if it's easier for you if I send it directly, please let me know.

David.
1 user thanked DavidArnoDandG for this useful post.
Remco on 8/18/2017(UTC)
EsbjornRedmo
#10 Posted : Thursday, August 17, 2017 7:05:21 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/17/2017(UTC)
Posts: 3
Location: United Kingdom

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Found a partial workaround: as long as the assembly with the actual tests target .net framework (net461 in my case), and the csproj file contains a <DependsOnNETStandard>true</DependsOnNETStandard> tag, I could get it to run code from a NetStardard2.0 project.
DavidArnoDandG
#11 Posted : Thursday, August 17, 2017 7:42:17 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/16/2017(UTC)
Posts: 6
Location: United Kingdom

Thanks: 1 times
Was thanked: 4 time(s) in 2 post(s)
Thanks EsbjornRedmo, that fixes the issue for me.
Remco
#12 Posted : Friday, August 18, 2017 7:07:33 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
3 users thanked Remco for this useful post.
yanglee on 8/18/2017(UTC), EsbjornRedmo on 8/18/2017(UTC), sextondjc on 8/20/2017(UTC)
sextondjc
#13 Posted : Sunday, August 20, 2017 12:34:45 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Still seem to be having a problem, unfortunately. Tried setting logging level to verbose but still only get the message below. This comes from Visual Studio 2017 Community version 15.3.1 using NCrunch 3.11.0.5 linked to above.

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.(ProcessorArchitecture , 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 , CustomEnvironmentVariable[] )
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.Processing.AnalysisTaskLogic.DoProcessTaskAndReturnSuccessFlag()

Not sure if this helps but I'm also using Resharper Ultimate as well as OzCode.
Remco
#14 Posted : Sunday, August 20, 2017 6:24:16 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
sextondjc;11010 wrote:
Still seem to be having a problem, unfortunately. Tried setting logging level to verbose but still only get the message below. This comes from Visual Studio 2017 Community version 15.3.1 using NCrunch 3.11.0.5 linked to above.

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.(ProcessorArchitecture , 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 , CustomEnvironmentVariable[] )
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.Processing.AnalysisTaskLogic.DoProcessTaskAndReturnSuccessFlag()


This looks to be a different problem. This exception is thrown when the .NET Core test process can't initialise and automatically terminates.

Where I've seen this in the past, it's been because of missing dependencies. It's possible there's something in your environment that NCrunch isn't accounting for.

Could you submit a bug report after you've seen this? The log file may yield something useful.

sextondjc
#15 Posted : Sunday, August 20, 2017 4:36:08 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Remco;11011 wrote:

This looks to be a different problem. This exception is thrown when the .NET Core test process can't initialise and automatically terminates.

Where I've seen this in the past, it's been because of missing dependencies. It's possible there's something in your environment that NCrunch isn't accounting for.

Could you submit a bug report after you've seen this? The log file may yield something useful.




Done. Can't see any missing dependencies but seems plausible as R# is also complaining about an unresolved reference (which it shouldn't).

I may well be doing something stupid, but can't see what that might be.
Remco
#16 Posted : Monday, August 21, 2017 12:26:59 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sending through the log. This contained an interesting exception:

System.Exception: Could not resolve assembly: System.Threading.Thread, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aSystem.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Thread, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Threading.Thread, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at nCrunch.TaskRunner.Ipc.Fast.FastIpcServer..ctor(SerializationContract contract, String ipcName, Boolean stringCachingAllowed)
at Program.startTaskRunner(Int32 ownerProcessId, String callbackUri, String externalProcessId, FilePath taskAssemblyPath, String taskComponentFullName, DirectoryPath appDomainBaseDirectory, Boolean stringCachingAllowed)
at Program.Initialise(String[] args)
at Program.Main(String[] args)

NCrunch should normally be trying to restore its dependencies earlier in the session. Has it given you any other warnings or errors worthy of note?

Simply creating a new project and adding the System.Threading.Thread v4.1 Nuget package should make VS restore this and place it in your Nuget local storage directory. NCrunch should then work for you, though it is still a mystery to me why NCrunch couldn't handle this earlier in the process.
sextondjc
#17 Posted : Wednesday, August 23, 2017 8:05:52 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Remco;11017 wrote:

NCrunch should normally be trying to restore its dependencies earlier in the session. Has it given you any other warnings or errors worthy of note?

Simply creating a new project and adding the System.Threading.Thread v4.1 Nuget package should make VS restore this and place it in your Nuget local storage directory. NCrunch should then work for you, though it is still a mystery to me why NCrunch couldn't handle this earlier in the process.


No joy. Tried that, same result. I think that exception was actually from ReSharper (2017.1.3, have since moved to EAP version as recommended here).

Does appear to be an NCrunch problem. I created a small test solution to try out against a couple of different test frameworks and runners. Observations below.

xUnit (fails)
• Build fails immediately as soon as the xUnit nuget package is reference.
• NCrunch reports the build as failed with the IpcConnectionClosedException pasted above. This is before writing a single line of code.
• I've tried this both with using the xUnitProject template as well as with a blank Core assembly and then adding xUnit via nuget.
• The test assembly is actually built and available in the test folder (AppData\Local\NCrunch\....).
• Needs Microsoft.NET.Test.Sdk to show up in Visual Studio Test Explorer.
• Test runs successfully with Visual Studio Test Explorer.
• Test runs successfully with ReSharper Dot Cover.

MsTest (fails)
• Builds successfully but fails the test with same IpcConnectionClosedException before actually executing the test.
• Needs Microsoft.NET.Test.Sdk to show up in Visual Studio Test Explorer.
• Test runs successfully with Visual Studio Test Explorer.
• Test runs successfully with ReSharper Dot Cover.

NUnit (succeeds)
• Seems to be unaffected, provided the NUnit3TestAdapter v3.8.0 package is installed.
• Needs Microsoft.NET.Test.Sdk to show up in Visual Studio Test Explorer.
• Test runs successfully with Visual Studio Test Explorer.
• Test runs successfully with ReSharper Dot Cover.

I've copied the test solution along with verbose NCrunch Diagnostic Output to here.

Hope that helps.
Remco
#18 Posted : Wednesday, August 23, 2017 11:46:38 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
I don't seem to be seeing the same thing as you are for these scenarios, so probably this problem is related to your system installstate or environment. Could you check which versions of the System.Threading.Thread library you have installed in your user's Nuget package storage directory? (i.e. C:\Users\[USER]\.nuget\packages\System.Threading.Thread). I think this is being caused by changes to .NET Core's assembly resolution system.
sextondjc
#19 Posted : Thursday, August 24, 2017 5:23:10 PM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Remco;11045 wrote:
I don't seem to be seeing the same thing as you are for these scenarios, so probably this problem is related to your system installstate or environment. Could you check which versions of the System.Threading.Thread library you have installed in your user's Nuget package storage directory? (i.e. C:\Users\[USER]\.nuget\packages\System.Threading.Thread). I think this is being caused by changes to .NET Core's assembly resolution system.


I have 4.0.0 and 4.3.0. Same ones as on nuget.

Have reinstalled core SDK. Issue remains. Reckon I'll just re-image my machine and try again. Maybe an unrelated dodgy install broke something somewhere. Will start from scratch and try again.
Remco
#20 Posted : Thursday, August 24, 2017 11:56:16 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
sextondjc;11060 wrote:

I have 4.0.0 and 4.3.0. Same ones as on nuget.

Have reinstalled core SDK. Issue remains. Reckon I'll just re-image my machine and try again. Maybe an unrelated dodgy install broke something somewhere. Will start from scratch and try again.


I'm getting reports of a whole range of assembly resolution issues related to changes in the latest version of .NET Core that was released a week or so ago. I'm going to have a dig around to see if I can reproduce any of these to provide closer alignment. I'll update you as soon as I have a build available.
1 user thanked Remco for this useful post.
sextondjc on 8/25/2017(UTC)
Users browsing this topic
Guest
3 Pages123>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.152 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download