1

I'm working on an application consisting of several projects and using EntityFramework with dotConnect to run against PostgreSQL. I also have a license for dotConnect which successfully works in the main application.

In parallel, I'm crafting a console application(a different solution) using Benchmark.Net to measure the performance of the logic of one of the projects. But every time I run the benchmark I'm getting the error below:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> Devart.Data.PostgreSql.PgSqlException: Assembly that contains embedded dotConnect for PostgreSQL license cannot be used with this application: 0f238e83-669a-46b8-876f-40331880ee79.exe.exe.

Following this instruction, I have already generated licenses.licx through Visual Studio and <exe file>.licenses via lc.exe. But it is still producing the same error.

I'm suspecting that the fact that Benchmark.NET generates its own exe to run the benchmark causing this error but I'm not 100% sure. So I'm looking for a solution if anybody has one?

Thank you

Dmitry Senin
  • 45
  • 1
  • 7

1 Answers1

3

I'm not sure it's a good idea to create a benchmark for code that does database calls etc. You're benchmarking not the code then, but your whole system instead: the file system, the database drivers, possible interop stuff, and so on.

This is not the idea of BenchmarkDotNet. It's actually created for benchmarking of relatively small CPU-bound tasks to find bottlenecks and perform optimizations based on measurements.

However, if you still want to do that, a solution might be to run the benchmark in-process of the console app you've created, without producing special benchmarking assemblies.

To do so, use the [InProcess] attribute. Just apply it to your benchmark class instead of usual job attributes:

[InProcess]
public class TypeWithBenchmarks
{
    [Benchmark]
    public void BenchmarkedMethod()
    {
    }
}
dymanoid
  • 14,771
  • 4
  • 36
  • 64
  • That worked. Thank you a lot. As for the benchmark itself, well, despite the fact that I agree that BenchmarkDotNet is designed for micro-benchmarking, I have to highlight that the logic I'm testing is quite lightweight and I have already found a performance problem in it using BenchmarkDotNet. So I think so far it meets all my needs – Dmitry Senin Nov 13 '18 at 16:59
  • 1
    After applying the fix I got `Unhandled Exception: System.InvalidOperationException: List of measurements contains no elements`. It is a BDN bug which seems to be fixed in 0.11.2.849. To install this nightly build, follow the instructions: https://benchmarkdotnet.org/articles/guides/nuget.html#nightly – Dmitry Senin Nov 13 '18 at 19:25