confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
80 stars 866 forks source link

Automatic load for librdkafka libraries not working in NetFramework projects with 2.6.0 #2328

Open dmalanij opened 4 weeks ago

dmalanij commented 4 weeks ago

Description

When using the libraries in Net 4.8 project (in particular a WebAPI), as of 2.6.0 the initialization of the Confluent.Kafka.Impl.Librdkafka initialization fails with a DllNotFoundException and the message:

Failed to load the librdkafka native library.

How to reproduce

In a NetFramework project, reference to the latest version of the Confluent.Kafka package; as soon as the runtime reaches the Kafka initialization (ie: using the ProducerBuilder<,>) the exception is thrown even if the redist assemblies are in place (in particular in the bin\librdkafka as the librdkafka.redist package targets take care of).

Root cause Analysis

I believe that the problem is hapenning because 2.6.0 has not included the target for net462; therefore the initialization goes through the netstandard variation without the automatic path resolution that is present for the cases of net462.

Workaround

This can be avoided by simply including a call to Library.Load(path) where path contains the location for the librdkafka.dll (which in case can be ~ripped of~ inspired by the logic used by the implementation of the LoadNetFrameworkDelegates.

UBSaxo commented 2 weeks ago

We face same blocking issue. I cloned Confluent.Kafka and could easily reproduce it simply by changing the target framework of Confluent.Kafka.UnitTests test project to net48 and then loads of tests fail with the DllNotFoundException.