Search Unity

Question Code in Assembly Definitioon Asset can not use Code in default Assembly-CSharp

Discussion in 'Scripting' started by jukka1993, May 31, 2023.

  1. jukka1993

    jukka1993

    Joined:
    Apr 29, 2021
    Posts:
    2
    There is a script ---------> Assets/AppConst.cs upload_2023-6-1_0-14-14.png

    and a Assembly-Definition Asset -----> Assets/HotUpdate/HotUpdate.asmdef upload_2023-6-1_0-15-59.png

    and a Script ---> Assets/HotUpdate/ResourceManager.cs
    upload_2023-6-1_0-18-11.png

    but, i can not use AppConst in ResourcesManager, there is an error ----> "Assets\HotUpdate\ResourcesManager.cs(8,13): error CS0103: The name 'AppConst' does not exist in the current context"
    upload_2023-6-1_0-19-20.png

    How to fix it ?
    Can any body help me? Thanks a lot!!!
     
  2. JusteTools

    JusteTools

    Joined:
    Mar 19, 2021
    Posts:
    14
    This is intended, the default assembly has references to all assembly defined with an asset (unless you explictly disable it), and therefore assembly defined with an asset cannot reference the default assembly (this would make a circular reference).

    This image show how to usually deal with this issue:

    Here you could have the AppConst script in its own assembly accessible from both the default assembly and referenced by your HotUpdate assembly.

    If this is not possible, (I had a similar issue where I needed to access user made class from an assembly, that therefore could not reference stuffs that didn't exist yet), you can always access any class using reflection !
     
    jukka1993 and Bunny83 like this.
  3. jukka1993

    jukka1993

    Joined:
    Apr 29, 2021
    Posts:
    2
    ok, I create another Assembly Definition Asset contain AppConst, thank you very much!