Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Conflict between UnityEngine Jetbrains.Annotations and NuGet .dll

Discussion in 'Scripting' started by EternalClickbait, Jul 19, 2020.

  1. EternalClickbait

    EternalClickbait

    Joined:
    May 5, 2019
    Posts:
    22
    I'm working on a library to share between several of my projects, and it requires the
    JetBrains.Annotations
    . I'm trying to use my library in a Unity project, but I can't because I keep getting ambiguous reference errors because Unity includes it's own set. Is thereany way to fix this? Even using extern aliases, I still can't get it to properly work.
     
  2. bentontr

    bentontr

    Joined:
    Jun 9, 2017
    Posts:
    39
  3. EternalClickbait

    EternalClickbait

    Joined:
    May 5, 2019
    Posts:
    22
    @bentontr I did, but it simply refused to differentiate the types in some cases.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Just use a
    using
    directive for types hwere there's a conflict. A common one in Unity is System.Random vs UnityEngine.Random. So you pick the one you want and use a using directive, a for example:

    Code (CSharp):
    1. using Random = UnityEngine.Random;
     
  5. EternalClickbait

    EternalClickbait

    Joined:
    May 5, 2019
    Posts:
    22
    UPDATE: My hackish solution was to remove the reference to the NuGet JetBrains.Annotations, and embed them in my shared library's source code instead.
     
  6. EternalClickbait

    EternalClickbait

    Joined:
    May 5, 2019
    Posts:
    22
    That won't work. The problem is namespace collision. Both Unity's set and the NuGet set have the exact same classes in the exact same namespace. That's why i tried extern alias.
     
    PraetorBlue likes this.