vstest: System.MissingMethodException Method not found: 'Void Microsoft.VisualStudio.CodeCoverage.Shim.1017596829__coverage_runtime_method__32412_19337__(UInt64)'.

Description

When using the /Enablecodecoverage option on vstest.console.exe, we occasionally see a MissingMethodException about the injected Shim method for the code coverage. This appears during calls than span across a new AppDomain.

i.e. System.MissingMethodException Method not found: ‘Void Microsoft.VisualStudio.CodeCoverage.Shim.2218451032__coverage_runtime_method__56282_18307__(UInt64)’.

Please this this related post we created about 4 years ago. This post is slightly different because it’s dealing with IIS, but might be related due to dealing with AppDomains. https://social.msdn.microsoft.com/Forums/vstudio/en-US/3f7415ed-7e17-496b-b705-3055c48a4406/iis-codecoverage-occasional-method-not-found-microsoftvisualstudiocodecoverageshim?forum=vsunittest

Steps to reproduce

Develop a unit test that makes a call across an app domain. You’ll occasionally see this exception (not always).

Expected behavior

There should be no exception

Actual behavior

We see the MissingMethodException

Diagnostic logs

Example failed test stack trace:

Failed SaveTwitterSearchData

Test method UnitTests.SocialTests.SaveTwitterSearchData threw exception: System.ServiceModel.FaultException`1[CompAnalytics.Contracts.Fault.ExecutionFault]: Exception has been thrown by the target of an invocation. Stack Trace:

Server stack trace: System.Reflection.TargetInvocationException Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) at System.AppDomain.InternalCreateInstanceFromWithNoSecurity(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes) at System.AppDomain.InternalCreateInstanceFromWithNoSecurity(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes) at System.Activator.CreateInstanceFrom(AppDomain domain, String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at CompAnalytics.Execution.Isolation.SandBox…ctor(ExecutionContext context) in C:\agent_work\1\s\Product\CompAnalytics.Execution\Isolation\SandBox.cs:line 91 at CompAnalytics.Execution.Isolation.SandBox.Create(ExecutionContext context) in C:\agent_work\1\s\Product\CompAnalytics.Execution\Isolation\SandBox.cs:line 52 at CompAnalytics.Execution.Isolation.SandBoxExtension.Create() in C:\agent_work\1\s\Product\CompAnalytics.Execution\SandBoxExtension.cs:line 15 at CompAnalytics.Execution.CodeModuleExecutor.Execute(IExecutionContext context) in C:\agent_work\1\s\Product\CompAnalytics.Execution\CodeModuleExector.cs:line 76 at CompAnalytics.Execution.ExecutionContext.ExecuteModuleWithRetry(ModuleExecutor executor, Module module) in C:\agent_work\1\s\Product\CompAnalytics.Execution\ExecutionContext.cs:line 1066 at CompAnalytics.Execution.ExecutionContext.ExecuteModule(ModuleExecutor executor, Module module, ExecutionCallback postExecutionCallback) in C:\agent_work\1\s\Product\CompAnalytics.Execution\ExecutionContext.cs:line 900 System.MissingMethodException Method not found: ‘Void Microsoft.VisualStudio.CodeCoverage.Shim.2218451032__coverage_runtime_method__56282_18307__(UInt64)’. at CompAnalytics.Execution.Isolation.RemoteSandBox…ctor(IsolatedTraceRedirector traceRedirector) at CompAnalytics.IServices.ClientMessageInspector.AfterReceiveReply(Message& reply, Object correlationState) in C:\agent_work\1\s\Product\CompAnalytics.IServices\ErrorHandler.cs:line 161 at System.ServiceModel.Dispatcher.ImmutableClientRuntime.AfterReceiveReply(ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

Environment

Windows Server 2012 R2 Test Execution Command Line Tool Version 14.0.25463.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 27 (9 by maintainers)

Most upvoted comments

There is 1 more way of fixing the issue in case of .NET Core, .NET Standard and .NET 5: you can start using unverifiable probes. Unverifiable probes don’t require Microsoft.VisualStudio.CodeCoverage.Shim dependency.

To enable unverifiable probes please set in your runsettings:

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
......
            <UseVerifiableInstrumentation>False</UseVerifiableInstrumentation>
......
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

If you don’t use runsettings you can add -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CodeCoverage.UseVerifiableInstrumentation="False" suffix to your command. For example:

dotnet test --collect "Code Coverage" --diag "log.txt" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CodeCoverage.UseVerifiableInstrumentation="False"

We will make unverifiable probes default for all .NET Core and .NET 5 projects in VS 16.10.

FYI

After downgrading packages in our test projects issue has not reproduced:

    <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.9" />   ->  "3.1.4"
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />            ->  "16.6.1"
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">            ->  "2.4.1"