SteveGilham / altcover

Cross-platform coverage gathering and processing tool set for dotnet/.Net Framework and Mono
MIT License
494 stars 17 forks source link

ERROR *** Instrumentation phase failed - Failed to resolve assembly: System.Data.Common #220

Closed binosheen97 closed 1 month ago

binosheen97 commented 2 months ago

Hi,

I am getting this error. Any solution?

Creating folder /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/Instrumented/ Instrumenting files from /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/ Writing files to /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/Instrumented/ Creating folder /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/_Reports

=> /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/Dapper.dll => /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/AE.exe => /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/NUnit3.TestAdapter.dll => /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/AETool.Test.dll

Coverage Report: /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/_Reports/coverage.xml

/home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/__Instrumented/NUnit3.TestAdapter.dll
            <=  NUnit3.TestAdapter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null
/home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/__Instrumented/Dapper.dll
            <=  Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null

Resolved assembly reference 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' as file '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.7/System.Data.dll'.

ERROR *** Instrumentation phase failed

Failed to resolve assembly: 'System.Data.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Details written to /home/jenkins/agent/workspace/l_AETool_feature_US191919/Tool_AETool/bin/Debug/__Instrumented/AltCover-2024-04-26--10-11-19.log

script returned exit code 255

SteveGilham commented 2 months ago

If this is a .Net Framework/Mono application then specifying --dependency=/path/to/System.Data.dll (the path being in the GAC_64 area, on Windows, at least) will override the heuristic for looking up unresolved references that has led down this path, and point the resolution at the correct assembly.

binosheen97 commented 2 months ago

Just for your information...

In my C# .Net Framework v4.8 project, I have installed few packages including Nunit console runner and Dapper. When i build the solution, i am not getting any error but in jenkins (linux environment) while intrumentation i am getting the below error. If i remove any one of this packages, then i am not getting the below error.

ERROR *** Instrumentation phase failed Failed to resolve assembly: 'System.Data.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

SteveGilham commented 2 months ago

In my C# .Net Framework v4.8 project

I expected as much. The underlying issue is Mono.Cecil's need to have a fully resolved type definition before it will write out an assembly that uses that type. It will automatically look for assemblies in the same folder as the one being processed, but otherwise has to be hand held. The resolution heuristic has found the dotnet version of System.Data.dll with the appropriate name, but that's just a facade, that says that the type being sought is in some version of System.Data.Common.dll.

I'm not going to try and guess what the precise environmental quirks are that are causing the differences in behaviour (possibly a VM being instantiated with or without some specific dotnet installed?), but feeding the instrumentation the System.Data.dll assembly it needs, either by tweaking the build parameters to get it copied to the build output directory, or by specifying where it can be found via --dependency=, will prevent the heuristic from making a guess.

binosheen97 commented 2 months ago

I noticed that using older version of altcover not throwing any error.

Failed to resolve assembly System.Data.Common:-

sh "nuget install altcover -o ${Tool}/packages"

I am installing the altcover with the above command. So it is installing latest version of altcover. (version 8.8.21)

mono Tool_AETool/packages/altcover.8.8.21/tools/net472/AltCover.exe --reportFormat=OpenCover --attributeFilter=ExcludeFromCodeCoverage --linecover -r Tool_AETool/_Reports/coverage.xml --outputDirectory=Tool_AETool/bin/Debug/__Instrumented -i Tool_AETool/bin/Debug --assemblyExcludeFilter=NUnit3.+ --assemblyExcludeFilter=nunit+ --assemblyExcludeFilter=Microsoft+

No Error:-

If i install older version using below command. Its working without any issues.

sh "nuget install altcover -o ${Tool}/packages -Version 8.6.95"

mono Tool_AETool/packages/altcover.8.6.95/tools/net472/AltCover.exe --reportFormat=OpenCover --attributeFilter=ExcludeFromCodeCoverage --linecover -r Tool_AETool/_Reports/coverage.xml --outputDirectory=Tool_AETool/bin/Debug/__Instrumented -i Tool_AETool/bin/Debug --assemblyExcludeFilter=NUnit3.+ --assemblyExcludeFilter=nunit+ --assemblyExcludeFilter=Microsoft+

SteveGilham commented 2 months ago

This may simply be another manifestation of the package issue already mentioned, as the different altcover versions involve different dependencies.

The attached is a pre-release which makes a search order for resolving non-local assemblies

  1. nuget cache
  2. GAC (incl Mono GAC)
  3. dotnet shared libraries

where Mono GAC includes /usr/lib/mono/gac and $MONO_GAC_PREFIX/lib/mono/gac as per https://www.mono-project.com/docs/advanced/assemblies-and-the-gac/ - this should help the heuristic; but at the end of the day just saying where the dependencies are is the only sure fix; and I can't do that, only you can.

altcover.8.8.34-pre-g1d815a6965.zip

binosheen97 commented 2 months ago

Thanks....This helped me to resolved the issue...

SteveGilham commented 2 months ago

In that case, that change is going into the next release.

SteveGilham commented 1 month ago

Released in v8.8.53