Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Reference to type 'AssemblyBuilderAccess' claims it is defined in 'mscorlib', but could not be found

Discussion in '2018.3 Beta' started by QFSW, Nov 16, 2018.

  1. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Hi, I was testing one of my plugins on 2018.3b to see if anything needed changing and this new error appeared when using the Assembly Builder from Reflection.Emit

    Code (CSharp):
    1. Assets\Plugins\QFSW\Quantum Console\CSharpCompiler\CustomDynamicDriver.cs(164,33): error CS0246: The type or namespace name 'AssemblyBuilder' could not be found (are you missing a using directive or an assembly reference?)
    2.  
    upload_2018-11-16_19-30-34.png

    I'm lead to believe that the issue is either:

    A) a bug with 2018.3b meaning the implementation is not found
    B) an intentional removal of the AssemblyBuilder
    C) The AssemblyBuilder has not yet been implemented to this beta build of 2018.3b

    If this is something that will not be present in the release version, then I don't need to take any further action. Is this intended however or not? and if it is intended how can we work around this?

    Many thanks
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Are you targeting .NET standard 2.0 API Compatibility profile? That is the new default I believe.
     
  3. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Ah! That was it, thanks!
     
  4. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Are there any preprocessors that allow us to determine which compatability level is used? I use #if NET_4_6 but this didn't trigger it :(
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  6. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    I think I've found a bug.

    In my normal assemblies, it works fine. However when I have an editor only assembly as specified by the asmdef, it stops working. Most likely due to the editor always using 4.x behind the hood, but then how can I use the equivalent preprocessor in the editor assembly? (the inspector wont work if the non editor class doesn't exist)

    I can send you the project as a repro if you need it. I'm not sure if its a bug or if I'm being stupid
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Can you explain the setup and what stops working? I'm having a hard time picturing what you're trying to do.
     
  8. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    My plugin requires .NET 4 to function. So in each of my scripts I now have
    Code (CSharp):
    1. #if NET_4_6 && !NET_STANDARD_2_0
    2. #define QC_SUPPORTED
    3. #endif
    Then I wrap the code inside
    QC_SUPPORTED


    This works fine.

    My editor then checks if
    !QC_SUPPORTED
    , and shows a dialogue to upgrade the project. This is so if a user imports it without the correct settings, instead of an error they get a clear error and a button to upgrade for them. This is done like this:
    Code (CSharp):
    1. #else
    2.         public override void OnInspectorGUI()
    3.         {
    4.             DrawBanner();
    5.             EditorGUILayout.HelpBox("NET 4.6 scripting backend is required for Quantum Console. Please upgrade/switch to the correct .NET backend before attempting to use Quantum Console.", MessageType.Error, true);
    6.  
    7.             GUILayout.BeginHorizontal();
    8.             GUILayout.FlexibleSpace();
    9.             if (GUILayout.Button("Upgrade Project to NET 4.6", GUILayout.Width(170)))
    10.             {
    11.                 PlayerSettings.scriptingRuntimeVersion = ScriptingRuntimeVersion.Latest;
    12.  
    13.                 string projectPath = Application.dataPath.Replace("Assets", string.Empty);
    14.                 EditorApplication.OpenProject(projectPath);
    15.             }
    16.             GUILayout.FlexibleSpace();
    17.             GUILayout.EndHorizontal();
    18.         }
    19. #endif
    This however, doesn't seem to be working. The asmdef for the editor code is set to only include the editor platform. If i remove the asmdef, or make it include build targets, it works again.
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    So I guess what you're trying to say is that if an asmdef is set to editor only, it's compiled as .NET 4.6, but if it's set to be included in players, it's compiled as whatever API compatibility level is specified in the player settings?
     
  10. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    From my understanding and testing, yes, but I may be wrong. Even if this is intended behaviour, I then still need a compile time way to check the projects API level
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I asked people from our scripting team to look at this thread as it's unfortunately outside my area of expertise.
     
  12. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    No worries, thanks for the help!
     
  13. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Hi @QFSW
    It is true that the defines set are not correct. I will make sure you can use the NET_4_6 preprocessor in Editor only assemblies in next 2018.3 version
     
    Last edited: Nov 17, 2018
  14. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Ah so it's just a beta bug then? If so that's all fine, I don't officially support beta builds so as long as it fixed for the final 2018.3 release that's fine!
     
  15. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @QFSW sorry, I thought this was another case that we previously had, where defines where not correct.
    So the defines are correct.
    But I understand your scenario. You could put your code in a nonEditor only asmdef, and wrap it with #if Editor
    Or you could do a combo with the NET_4_6 define and check on the playersetting compatibility
    PlayerSettings.GetApiCompatibilityLevel
     
  16. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    The problem is my code won't compile since it references stuff from the non editor code that doesn't exist
     
  17. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
  18. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    That looks interesting. I could give it a try And yeah there's definitely work arounds, but it just feels like an oversight that would be nice to have a more native solution for
     
  19. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
  20. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Yes, it will behave the same.

    So The defines are the truth of how this assembly will get compiled. We will not add global defines like this.
     
    LeonhardP likes this.
  21. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Awesome, thanks