Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetMQ in Unity3D - System.Runtime.CompilerServices.Unsafe dependency problem #944

Open
sibsutispds opened this issue Oct 12, 2020 · 2 comments
Labels

Comments

@sibsutispds
Copy link

Environment

NetMQ Version:  4.0.1.6  
Operating System: MacOS Catalyna 10.15.6 
.NET Version:  4.7 (API Compatibility level .NET 4.x )   

Expected behaviour

Be able to send and receive messages in Unity3D using NetMQ.

Actual behaviour

First things first, thank you for a wonderful tool! NetMQ is a great and easy to use port of ZeroMQ - it's a lifesaver!

Now, to the issues I'm experiencing.

When I install NetMQ 4.0.1.6 from NuGet and add it into the Unity3D project it asks for a System.Runtime.CompilerServices.Unsafe 4.0.4.1 dll. Here's the error from Unity3D:

FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
NetMQ.Msg.Slice (System.Int32 offset) (at :0)
NetMQ.Core.Patterns.XSub.XSend (NetMQ.Msg& msg) (at :0)
NetMQ.Core.Patterns.Sub.XSetSocketOption (NetMQ.Core.ZmqSocketOption option, System.Object optionValue) (at :0)
NetMQ.Core.SocketBase.SetSocketOption (NetMQ.Core.ZmqSocketOption option, System.Object optionValue) (at :0)
NetMQ.NetMQSocket.SetSocketOption (NetMQ.Core.ZmqSocketOption option, System.Object value) (at :0)
NetMQ.Sockets.SubscriberSocket.Subscribe (System.String topic) (at :0)
Veneris.Vehicle.Sivert_API_GSCM.Start () (at Assets/Scripts/Veneris/Vehicle/Sivert_API_GSCM.cs:252)

After I manually add required System.Runtime.CompilerServices.Unsafe.dll dll into the project I get the following error:

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name System.Runtime.CompilerServices.Unsafe.dll included for the current platform. Only one assembly with the same name is allowed per platform. Assembly paths: Assets/Plugins/NetMQ.4.0.1.6/System.Runtime.CompilerServices.Unsafe.dll, /Users/nlyamin/WRK/Simulation/backups/SIVERT_Veneris_Unity_backup/Library/PackageCache/[email protected]/System.Runtime.CompilerServices.Unsafe.dll
UnityEditor.Scripting.ScriptCompilation.EditorBuildRules.CreateTargetAssemblies (System.Collections.Generic.IEnumerable1[T] customScriptAssemblies, System.Collections.Generic.IEnumerable1[T] precompiledAssemblies) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorBuildRules.cs:275)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation.UpdateCustomTargetAssemblies (System.Boolean forceUpdateAssetMetadata) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:732)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation.SetAllCustomScriptAssemblyReferenceJsonsContents (System.String[] paths, System.String[] contents) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:879)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.SetAllCustomScriptAssemblyReferenceJsons (System.String[] allAssemblyReferenceJsons, System.String[] allAssemblyReferenceJsonContents) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:241)

I believe it's because I already have System.Runtime.CompilerServices.Unsafe.dll as part of the Unity.Collections package (which depend on it). When I check, I see that Unity.Collections uses System.Runtime.CompilerServices.Unsafe 4.0.4.0. So Unity3D doesn't allow to add several .dll with the same name, could you recommend workaround for my problem?
Do you know if I could switch NetMQ dependency to System.Runtime.CompilerServices.Unsafe 4.0.4.0 and if yes, how it should be done?

Thank you in advance!

Steps to reproduce the behaviour

Install NetMQ 4.0.1.6 in Unity3D 2019. Also install any package in Unity3D dependent on System.Runtime.CompilerServices.Unsafe, e.g. Unity.Collections and try to implement simple RequestSocket/ResponseSocket.

@gianluco
Copy link

Hi,

I've experienced the same issue with version 4.0.5.0 being already loaded by my .NET framework application.

I've resolved it by using binding redirect (see https://stackoverflow.com/questions/62764744/could-not-load-file-or-assembly-system-runtime-compilerservices-unsafe/62770487)

Not sure though if you can use it in your context with Unity3D.

Hope it helps

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants