confluent-kafka-dotnet: System.DllNotFoundException: Failed to load the librdkafka native library

System.DllNotFoundException: Failed to load the librdkafka native library

An error occurred using the Dotnet core Web API Errors are as follows

Microsoft.AspNetCore.Server.Kestrel[13] Connection id “0HL9RN5T1D654”, Request id “0HL9RN5T1D654:00000001”: An unhandled exception was thrown by the application. System.DllNotFoundException: Failed to load the librdkafka native library. at Confluent.Kafka.Impl.LibRdKafka.Initialize(String userSpecifiedPath) at Confluent.Kafka.Producer…ctor(IEnumerable1 config, Boolean manualPoll, Boolean disableDeliveryReports) at Confluent.Kafka.Producer2…ctor(IEnumerable1 config, ISerializer1 keySerializer, ISerializer`1 valueSerializer, Boolean manualPoll, Boolean disableDeliveryReports)

How to reproduce

Use Asp.net Core WebApi on Centos7

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 36 (15 by maintainers)

Most upvoted comments

Hi guys, I am trying to do exactly what @sfrooster said - building netstandard2.0 lib used by a netcoreapp2.0 console app and it fails with aforementioned error on Windows 10, is there any resolution/solution to this yet?

I was helped with this code before creating the producer

try
{
	_producer = builder.Build();
}
catch (DllNotFoundException)
{   // Загрузка злоебучей librdkafka.dll
	if (!Library.IsLoaded)
	{
		var pathToLibrd = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
			$"librdkafka\\{(Environment.Is64BitOperatingSystem ? "x64" : "x86")}\\librdkafka.dll");
		_log.Info($"librdkafka is not loaded. Trying to load {pathToLibrd}");
		Library.Load(pathToLibrd);
		_log.Info($"Using librdkafka version: {Library.Version}");
	}
	_producer = builder.Build();
}

@mhowlett “brew install openssl” fixed everything such that he also no longer needs to explicitly call Load.

As for versions, he’s on osx 10.13.3, dotnet cli 2.2-preview/2.1, mono 5.8, Confluent.Kafka 0.11.3, building a netstandard2.0 lib used by a netcoreapp2.0 console app.

if the library is installed via our packages or from source as instructed it will be in a standard path, and I think you should be able to load it using just Library.Load("librdkafka.so") (note: if you just installed it, you may need to call ldconfig to update the cache).

or you can deploy a redhat compatible binary along with your app and use an absolute / relative path.

this one really saved me… my issue was that i had to dockerize an C# app that use Confluent.Kafka 1.5.3

RUN cd /tmp \ && wget https://github.com/edenhill/librdkafka/archive/refs/tags/v1.9.0.zip \ && unzip v1.9.0.zip \ && cd librdkafka-1.9.0 \ && ./configure --install-deps \ && make \ && make install \ && ldconfig

without adding ldconfig didn’t worked

It’s a new mbp, whereas mine is probably 1.5 years old?