Closed latop2604 closed 5 months ago
The quick work-round is to exclude the Microsoft assemblies from instrumentation. Since it is unlikely that coverage data from those assemblies will be of interest, rather than being clutter, I've not dug deeply into what is going on with the cross-assembly calls in the test platform assemblies. Rather, when I first encountered it on one of the preview releases, I just added that exclusion to my own tests.
I tried to add -e Microsoft -e testhost -e xunit
to instrumentation line (./tools/altcover -e xunit ...
), but It does not fix the issue.
Is it what you suggested by "exclude the Microsoft assemblies from instrumentation" ?
I downgraded Microsoft.NET.Test.Sdk from 17.8.0 to 17.6.2 and it seem to work again
The executive summary:
As the Microsoft code has no references to your code, you want -s testhost -s Microsoft
; the difference being that -s
leaves the excluded assemblies completely alone, whereas -e
is a (slightly obsolescing) work-round that does interfere with them.
Background information:
Having repro'd the issue again and decompiled the affected assemblies, it turns out that it is, as I had guessed, to do with assembly strong-names -- the code in testhost.dll
that throws is invoking a contructor in Microsoft.TestPlatform.CoreUtilities.dll
that it has access to only via an InternalsVisibleToAttribute
; that attribute of course implies the full assembly name for testhost.dll
, including the strong-name.
The -e
filter is itself a strong-naming workround, rewriting assembly references in the nominated files, at the cost of also rewriting their strong names, and is intended for libraries that link your code under test directly (e.g. for excluding unit test code from coverage when applying a non-production strong-name during test).
Obviously, not having the Microsoft strong-name key means not being able to rewrite the assembly with the original strong name, thus breaking the InternalsVisibleTo
.
AltCover doesn't rewrite those attributes, though it could, because I've not yet found an appropriate use-case; here the correct thing to do is exclude those linked assemblies.
Added work item to update [InternalsVisibleTo]
If you are building using the dotnet.exe test command adding the flag /p:AltCoverAssemblyFilter="testhost|Microsoft" seems to resolve it also as per SteveGilham comments but using the dotnet test syntax.
The general issue of which this is a specific case should be resolved in release v8.6.125.
Hello, I try to migrate my app from net7 to net8, but it seem to fail. I'm using altcover.global v8.6.95.
I use the following command:
And the I got the following error :
The coverage seem to work with coverlet.
Do you think it could be related to altcover it self and if not, advise on what could be wrong ?
Thx