Build/Test Issues

nCrunch and PostSharp

Started by TURNSKIN on 1,783 views

Hi,
I am getting this error:
Services.csproj (0, 0): The custom attribute 'Infrastructure.PostSharp.CheckUserPrivilegeAspectAttribute' constructor threw the exception FileNotFoundException: Could not load file or assembly 'nCrunch.TestRuntime.DotNetCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea'. The system cannot find the file specified.


How can I solve this issue?
gacutil -i nCrunch.TestRuntime.DotNetCore.dll
gacutil /l nCrunch.TestRuntime.DotNetCore


C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2022>gacutil /l nCrunch.TestRuntime.DotNetCore
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.

The Global Assembly Cache contains the following assemblies:
nCrunch.TestRuntime.DotNetCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea, processorArchitecture=MSIL

Number of items = 1


but still the same issue occurs.
Hi, thanks for sharing this issue.

This problem is occuring because postsharp is executing code that has been instrumented by NCrunch. The GAC workaround won't work in this scenario, probably because the environment used by Postsharp doesn't include the GAC in its search path.

Something you can try is to add a direct reference to the nCrunch.TestRuntime.DotNetCore.dll assembly from the project containing the instrumented code. This would cause the build system to copy the file to the build output directly where hopefully Postsharp can include it in its search path. To avoid making this a dependency for your non-NCrunch builds, you could make it conditional, for example:

<ItemGroup Condition="'$(NCrunch)' == '1'">
<Reference Include="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2019\nCrunch.TestRuntime.DotNetCore.dll" />
</ItemGroup>

Post a reply

Log in to reply.