• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by xxmariofer · Jun 17, 2020 at 08:05 AM · referencedllassemblydllimport

Multiple DLL with the same class reference

Hello, I am using t$$anonymous$$rd party libraries in my projects, one is

Diagflow for Unity and the second is Ros for Unity

My issue comes with the fastJSON.dll and NewtonSoft.Json.dll they both are sharing classes namespaces and i get the error

"The class X exist in both LIBRARY1 and LIBRARY2"

if i remove one of the 2 libraries errors dissapear, BUT there are t$$anonymous$$rd libraries that depend to both libraries, so if i remove one i can run the project but i get the error

"THIRDASEMBLY can not be load because it cant locate (THE LIBRARY I HAVE JUST DELETED)"

I cant modify those libraries since they are t$$anonymous$$rdparty, I have tried adding an extern alias following t$$anonymous$$s example without success

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Bunny83 · Jun 17, 2020 at 02:23 PM

I haven't really used any of the libraries you've mentioned. However I doubt that there are actual type name collisions between those libraries. As far as I can tell the NetwonSoft library has all its classes inside its own namespace (Newtonsoft). So you could only get name collisions when you put two using statements of different namespaces inside the same file, or if the other library abusively uses the Newtonsoft namespace for its own class(es).


T$$anonymous$$s is of course just an example. I haven't actually used the libraries. You haven't mentioned the actual classes and namespaces involved here. Are you sure you did not just mindlessly put up using statements? One of the most common example that doesn't involve any t$$anonymous$$rd party libraries is the Random class. Unity has it's own Random class inside the namespace UnityEngine. However there's also a Random class inside the System namespace. They can happily co-exist next to each other. However you can not use both using statements at the same time. So using UnityEngine; and using System; is not possible at the same time when you want to refer to the Random class. In that case you have to use the full qualified classname, including the namespace.


If the two libraries in fact define a class with the same name inside the same namespace, you could simply blame the creators of those libraries. You said you tried the library alias solution. Did you actually create the [compiler configuration file "smcs.rsp"][1] and specify alias names for your two libraries?


As I mentioned since your question is lacking the actual details of your error / issue I will not go further into t$$anonymous$$s. You can not expect us to download and import the libraries outselfs just to see what's the actual issue.


ps: I often get the impression that some people t$$anonymous$$nk a using statement is somehow required to use a certain library. T$$anonymous$$s is completely false. Using statements at the top of a file just make a namespace available for t$$anonymous$$s file for convenience so you don't have to type out the namespace all the time. A namespace also does not necessarily be related to one particular library, though it commonly is w$$anonymous$$ch might be the reason for that assumption. Namespaces are just a way of organising and seperating classes wit$$anonymous$$n the app domain specifically to avoid name collisions between t$$anonymous$$rd party libraries. [1]: https://github.com/DashW/UnityExternAlias/blob/master/Assets/smcs.rsp

Comment

People who like this

0 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Jun 17, 2020 at 05:27 PM 0
Share

hello, sorry i should have added more resources to clarify my question, first i am adding an image showing the exact error i get

alt text

If its not legible (i chose that font size so i could add full script to the image) the exact error is:

alt text

The Class that is giving issues is for example: "Newton.Json.JsonIgnoreAtribute" and others "Newton.Json.X" classes

Thanks for pointing out the multiple using issue, but i indeed made sure that i wasnt adding multiple using statement, but to make sure here is a link to the apiaisdk github library that is using the namespace Newtonsoft.Json (from fastJSON) and here is a link to the rosharp library using that same namespace but from the Netwonsoft.Json dll.

into the extern alias issue i have added the alias to make sure i was using the correct Newtonsoft.Json class here is the resulted code, without showing any errors,

 extern alias test2;
 using test2::Newtonsoft.Json;
 
 namespace RosSharp.RosBridgeClient.MessageTypes.Sensor
 {
     public class SetCameraInfoResponse : Message
     {
         [JsonIgnore]
         public const string RosMessageName = "sensor_msgs/SetCameraInfo";
 
         public bool success;
         //  True if the call succeeded
         public string status_message;
         //  Used to give details about success
 
         public SetCameraInfoResponse()
         {
             this.success = false;
             this.status_message = "";
         }
 
         public SetCameraInfoResponse(bool success, string status_message)
         {
             this.success = success;
             this.status_message = status_message;
         }
     }
 }

but when unityeditor compiles the code it returns the next error:

(IT IS ATTACHED TO NEXT COMMENT IT DOESNT LET ME UPLOAD MORE THAN 2 FILES) so i searched and found about the smcs.rsp, i tried several times, without success, and when googling the error i found this

https://issuetracker.unity3d.com/issues/unity-compiler-ignores-reference-alias-in-rsp-files

so i imagined that was simply not supported in newer versions (i am using 2019) and my next approach was to come to unity forum in case someone could give me an advice

Sorry for the lack of details i was in a hurry i should not have upload the question like this.

@Bunny83 thanks for your time any advice, even if its to simply stop trying to find a solution and write my own library is appreciated.

Mario.

sin-titu2lo.png (7.0 kB)
sin-titulo.png (58.8 kB)
avatar image xxmariofer xxmariofer · Jun 17, 2020 at 05:29 PM 0
Share

alt text

4.png (7.1 kB)
avatar image Bunny83 xxmariofer · Jun 17, 2020 at 07:19 PM 0
Share

Well, I have never really used assembly alias names in Unity since I wasn't in need of them. It seems that Unity's compiler does not support assembly alias names. So your only other option would be to fix the issue at the source. To me it seems very strange that your fastJSON library actually contains classes from a completely different library. This seems to be a custom build of the fastJSON library. At least the version 2.2.0 of the fastJSON code project does not contain those namespaces (checked with ILSpy).


So you could try replacing the fastJSON.dll with a newer "official" one and see if it's compatible. If it's not you could probably decompile your fastJSON dll. remove all the classes and type definitions in the Newtonsoft namespace and replace the few uses with the actual classes from the proper Json.Net library. That means instead of shipping your own version of the attributes used by fastJSON, it would actually reference the Newtonsoft library to get access to those attributes. Though depending on if those attributes are actually used in your code, you might be able to just replace / rename them inside the fastJSON library source.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Windows Phone 8.1 Assembly 0 Answers

merged DLL not working 0 Answers

How do I get rid of "Assembly-CSharp-firstpass" and "Assembly-CSharp-firstpass.dll" from my Assets? 1 Answer

How do I find (and delete) variable type definitions? 1 Answer

Can/should mcs.rsp files be used to reference my own class libraries? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges