简体   繁体   中英

Using ZeroMQ in Portable Class Library .Net & Mono

I try to use ZeroMQ in new project.

Server and client must interact (exchange messages) through ZeroMQ. It is planned to implement several kinds of customers Android, Windows, may be another. I would like to make the basic logic of interaction in the PCL.

Visual Studio 2013 + Xamarin

I created PCL project, with NuGet installed clrzmq package. Created test method:

public  string M1()
{
     using (var c = new Context())
     {
           var subscriber = c.Socket(SocketType.SUB);
           subscriber.Bind(Transport.TCP, "192.168.123.23:9292");
           subscriber.Subscribe("", Encoding.UTF8); // subscribe to all messages
           var message = subscriber.Recv(Encoding.UTF8, SendRecvOpt.NONE);
           return message;
      }
}

When I call this method in Android project, I see DllNotFoundException. The problem described in this question (but for Android)

The code compiles, but in runtime - error DllNotFoundException for libzmq.dll.

Could you tell me how to configure linking libzmq properly?

After reading a post from xamarin , and from my experience with the limitations of PCL in Xamarin. This isn't an option. When you import tha ZeroMQ it adds binaries for X86 and amd64 into the project. These binaries allow it to work with the mono framework on X86/amd64 platforms, not arm(android/ios/windows phone).

Also in the Xamarin documentation of What is a Portable Class Library? it has the List of Disadvantages

  • Because the same Portable Class Library is shared between multiple applications, platform-specific libraries cannot be referenced (eg. Community.CsharpSqlite.WP7).
  • The Portable Class Library subset may not include classes that would otherwise be available in both MonoTouch and Mono for Android (such as DllImport or System.IO.File).

The DLLNotFoundException is probably coming from the lack of DllImport support

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM