System.MissingMethodException Unit Test

The presence of problems associated with the execution of the Link to the project in the Visual Studio 2017 Runner test. Unit Test CSPROJ builds just fine with TargetFramework=net47, but at run time we get the following message from MSTEST or XUNIT. Using Microsoft.NET.Test.Sdkv15.0.0.

Test Run Error (x86): Serilog Seq Extension

System.MissingMethodException: Method not found: "Serilog.LoggerConfiguration Serilog.SeqLoggerConfigurationExtensions.Seq (Serilog.Configuration.LoggerSinkConfiguration, System.String , Serilog.Events.LogEventLevel, Int32, System.Nullable 1<System.TimeSpan>, System.String, System.String, System.Nullable1, System.Nullable 1<Int64>, Serilog.Core.LoggingLevelSwitch, System.Net.Http.HttpMessageHandler, System.Nullable1, Boolean, Int32) '.

Unit Test Example - Serilog

[Fact]
public void TestMethod1()
{
    LoggerConfiguration loggerConfig = new LoggerConfiguration();    
    loggerConfig.MinimumLevel.Debug();                    
    loggerConfig.WriteTo.LiterateConsole();    
    loggerConfig.WriteTo.Seq("http://localhost:65454");    
}

net462, , , VS 2017, .NET Framework. VS 2015. , DLL- / .. - ?

nuget, - ProjectReference .NET Core CSPROJ. , .

KeyVault, VS Test Runner ...

(x86): KeyVault

: System.MissingMethodException: : 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(AuthenticationCallback, System.Net.Http.DelegatingHandler [])'.

Unit Test - KeyVault

[Fact]
public void TestMethod1()
{
    KeyVaultClient _kvClient = new KeyVaultClient(new AuthenticationCallback(getKeyVaultToken));
}

private static async Task<string> getKeyVaultToken(string authority, string resource, string scope)
{
    var authContext = new AuthenticationContext(authority);
    ClientCredential clientCred = new ClientCredential("test", "account");
    AuthenticationResult result = authContext.AcquireTokenAsync(resource, clientCred).Result;

    if (result == null)
        throw new InvalidOperationException("Failed to obtain the JWT token");

    return result.AccessToken;
}
+4
1

dotnet test . dotnet test --diag , , Microsoft.NET.Test.Sdk, 15.0.0 . nuget 15.3.0-preview-20170502-03, .

: Microsoft.Rest.ClientRuntime

System.TypeLoadException: " , :" System.Net.Http.WebRequestHandler ". , . '

- MissingMethodException , System.Net.Http. , , . nuget System.Net.Http 4.3.1, , .

Microsoft.NET.Test.Sdk System.Net.Http , MissingMethodException dotnet. github .

№ 2 -

VS 2017 CSPROJ , System.Net.Http Build Output, GAC'd 4.0.0.0.

<PackageReference Include="System.Net.Http" Version="4.3.1">
  <ExcludeAssets>All</ExcludeAssets>
</PackageReference>

№ 3 -

dotnet , app.config, nuget System.Net.Http 4.1.*, 4.0.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!-- Another PackageReference dependency binds to 4.1.1 which is busted, we leverage .NET Core redirection and revert to CLR 4.0.0 -->
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
+6

Source: https://habr.com/ru/post/1676764/


All Articles