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

Notification

Icon
Error

Couple of issues with solution with .NET Core project
kierenj
#1 Posted : Wednesday, July 26, 2017 2:17:43 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/25/2016(UTC)
Posts: 10
Location: United Kingdom

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Hi - first a quick note, my installation was somehow corrupted and I ended up doing a manual install. However, the "devenv /setup /novstemplates" step did not work (gave "Operation could not be completed") unless I ran with administrator privileges. It may be worth updating the documentation for VS2017 if this is the case for others too?

(I'm on 3.10 of NCrunch, and VS2017 15.3 Preview 3)

Anyway, I have a solution with .NET Core, .NET Standard and .NET Framework projects. It builds/runs fine, but I have a few problems with NCrunch:

1. ------ NuGet issue ------
NCrunch was unable to restore Nuget packages required to build a test environment for this project, due to an unspecified failure when invoking 'dotnet.exe restore'
C:\git\kierenj\diamond\backend\core\xxx\yyy.xxx
The following packages need to be restored because they do not exist under the Nuget packages folder for this user profile:

xunit.runner.utility v2.2.0


How can I help diagnose this one?

2. ------ "Analysis Failure" on .NET Framework class library ------

An error occurred while analysing this project after it was built: System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Net.Http.dll' or one of its dependencies. The system cannot find the file specified.
File name: 'file:///C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Net.Http.dll'
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)

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Net.Http.dll
LOG: Appbase = file:///C:/Users/kiere/AppData/Local/NCrunch/34504/29/core/xxx/yyy.xxx/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\kiere\AppData\Local\NCrunch\34504\29\core\xxx\yyy.xxxyyy.xxx.dll.config.ncrunchconfig
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

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 System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly)
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
at nCrunch.Module.NUnit.Integration.NUnitFrameworkRuntimeEnvironment.ensureRunnerExists(FilePath testAssemblyPath)
at nCrunch.Module.NUnit.Integration.NUnitFrameworkRuntimeEnvironment.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.TestFinder..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, DescribedTestFrameworkDiscoverer[] describedDiscoverers, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker)



The project builds/runs OK, without this message, so I'm not sure what to try? Note, this is after I added a redirect from 0.0.0.0-4.2.0.0 to 4.2.0.0 to the app.config (prior to that, it was doing the same for 4.1.0.0).

The project does have some warnings in both VS and NCrunch that some references (specifically, ones to .NET Core NuGet packages) have a mismatch between AMD64 and MSIL. In the csproj, the references DID have "AMD64", I have no idea why. I edited the csproj to point to MSIL, but the warnings persist. I don't know if this is relevant.
kierenj
#2 Posted : Wednesday, July 26, 2017 2:48:45 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/25/2016(UTC)
Posts: 10
Location: United Kingdom

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Weirdly, when I changed the consuming project (for the 2nd issue) to target .NET 4.6.1, the errors went away.

The first issue seemingly fixed itself too.
kierenj
#3 Posted : Wednesday, July 26, 2017 7:32:12 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/25/2016(UTC)
Posts: 10
Location: United Kingdom

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I now have the following, for a project which is using PostSharp, in a PostSharp aspect class.



Aspects\CallerIdNeededAttribute.cs (17, 18): An unexpected exception occurred when executing user code: System.TypeInitializationException: The type initializer for 'xxx.Auth.AccessControl.AppPermissions' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'nCrunch.TestRuntime, Version=3.10.0.20, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea' or one of its dependencies. The system cannot find the file specified.
at xxx.Auth.AccessControl.AppPermissions..cctor()
--- End of inner exception stack trace ---
at xxx.Auth.AccessControl.AppPermissions.get_Tree()
at xxx.Core.Services.Aspects.CallerIdNeededAttribute.EnsurePermissionClaims() in C:\Users\kiere\AppData\Local\NCrunch\12616\24\core\xxx.Core.Services\Aspects\CallerIdNeededAttribute.cs:line 30
at xxx.Core.Services.Aspects.CallerIdNeededAttribute.GetPolicyClaims() in C:\Users\kiere\AppData\Local\NCrunch\12616\24\core\xxx.Core.Services\Aspects\CallerIdNeededAttribute.cs:line 100
at xxx.Core.Services.Aspects.CallerIdNeededAttribute.CompileTimeValidate(MethodBase method) in C:\Users\kiere\AppData\Local\NCrunch\12616\24\core\xxx.Core.Services\Aspects\CallerIdNeededAttribute.cs:line 84
at PostSharp.Aspects.MethodLevelAspect.CompileTimeValidate(Object target)
at PostSharp.Sdk.AspectWeaver.AspectWeaverInstance.^pCdttYEs.^Q7McNsOl()
at PostSharp.Sdk.Utilities.ExceptionHelper.ExecuteUserCode[T](MessageLocation messageLocation, Func`1 userCode, Type[] acceptableExceptions).


I found this:

http://forum.ncrunch.net...unch-and-PostSharp.aspx

...which suggests the installer does some GacUtil magic. As above, I installed manually. So do I need to gacutil manually too?
kierenj
#4 Posted : Wednesday, July 26, 2017 9:10:36 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/25/2016(UTC)
Posts: 10
Location: United Kingdom

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Ok, that seemed to fix that issue.

To recap: I fixed all of the above. But maybe this thread will be useful for others searching for solutions :)


But I have a new issue:

Similar to http://forum.ncrunch.net...ageFormatException.aspx , I get:


System.BadImageFormatException : Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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)
----> System.BadImageFormatException : Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Net.Http.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)
----> System.BadImageFormatException : Cannot load a reference assembly for execution.


However, different from the other thread (I think) is that this is a .NET Framework unit tests project which references a .NET Standard class library.

The test project does reference System.Net.Http (4.3.0) directly, and there's a redirect in app.config to 4.1.1.0 (I also tried editing to 4.2.0.0 and get the same thing). Bit weird that it's looking for 4.2.0.0 when the redirect says 4.1.1.0 maybe.

I did a 'browse to workspace' and can confirm there's no .deps.json file or similar. Anything I can do to diagnose?
Remco
#5 Posted : Wednesday, July 26, 2017 10:56:47 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 664 times
Was thanked: 781 time(s) in 743 post(s)
Hi, thanks for posting.

kierenj;10854 wrote:
Hi - first a quick note, my installation was somehow corrupted and I ended up doing a manual install. However, the "devenv /setup /novstemplates" step did not work (gave "Operation could not be completed") unless I ran with administrator privileges. It may be worth updating the documentation for VS2017 if this is the case for others too?


Thanks for the heads up on this. I've updated the documentation accordingly.

kierenj;10854 wrote:

NCrunch was unable to restore Nuget packages required to build a test environment for this project, due to an unspecified failure when invoking 'dotnet.exe restore'


This is a generic error that NCrunch will give you if it's unable to download Nuget packages that are normally required for its runtime execution. NCrunch's runtime environment under .NET Core has a dependency on several Nuget packages that are needed to initialise the environment. Because the step to download them is not 100% reliable (due to potential for network issues or issues with preview tooling), it's possible that the download can fail. A simple solution to this is to yourself create a sample project with Nuget references to the packages listed by the error, and VS will then download them automatically in a place that NCrunch can find them.

Regarding nCrunch.TestRuntime installed in the GAC: It's true that the installer will do this, but it's not necessarily required for normal NCrunch function. You're likely being hit with an edge case in which the assembly is being loaded by a different process or application domain and NCrunch is unable to inject its custom logic for finding the assembly. In your case, installing the file in your GAC is a good idea.

Regarding other assembly resolution issues: Unfortunately with the release of .NET Core, the resolution of assembly references has now become so complex that it just isn't practical to try and troubleshoot it using this forum. There are too many variables involved. If you're able to construct a sample project that can reproduce the problem (and submit through the contact form) I'll be happy to take a look and give further advice.

Thanks also for taking the time to post your solutions here in the forum. It's of huge help to everyone when you do this :)
1 user thanked Remco for this useful post.
kierenj on 7/27/2017(UTC)
kierenj
#6 Posted : Friday, July 28, 2017 7:41:32 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/25/2016(UTC)
Posts: 10
Location: United Kingdom

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I'm trying to create a repro, but no luck yet. I have a unit test project referencing that nuget package, and another netstandard14 class library referenced with the reference too.

I do notice that it's nCrunch.Common.CustomAssemblyResolver.ResolveAssembly which is explicitly trying to load from the path file:///C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Net.Http.dll, which is a reference assembly.

In terms of that behavior, are there any hints you can share - like what would result in that happening, that might guide me finding a repro?


Edit: I found that running my tests using the nunit runner, I still get the errors. So it's unlikely to be anything specific to ncrunch. I'll see if I can fix and share here.

Edit: well, to fix this specific error, I updated a binding redirect:

<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />

Based on: https://github.com/dotnet/corefx/issues/9846


nunit console runner still borks, I have no idea why. But all good with ncrunch.
1 user thanked kierenj for this useful post.
Remco on 7/28/2017(UTC)
Users browsing this topic
Guest
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.095 seconds.