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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Add new reference in Assembly-CSharp

Discussion in 'Scripting' started by YiHan-GI, Apr 10, 2018.

  1. YiHan-GI

    YiHan-GI

    Joined:
    Mar 20, 2018
    Posts:
    9
    Hello, I have a Visual studio related question:

    Normally if you create a new C# Class Library(.Net framework) project from VS, you can always add new reference to it.

    But today I just find out, that if I create a new Unity project, and open the .cs file with VS, I can not add any new reference/dll file through VS's solution explorer window, like the screenshot I uploaded here: this is a unity project, when I right click on the "References" folder, not like a C# project, there is no "Add Reference" button in the menu.

    My question is, except of dragging and dropping dll files into unity's assets folder, is there other way to add new reference via VS?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    In the Unity environment you don't make the C# project. Under Unity's menu you just use Assets-> Open C# project and Unity will generate one with everything you need based on what is in your project directory. It saves you a TON of hassle fiddling with C# projects: all you need to do is throw your DLLs and source into the Unity project. There are some rules but it works pretty seamlessly honestly. And it means you don't have to add any of that C# project cruft to your source control either.
     
  3. YiHan-GI

    YiHan-GI

    Joined:
    Mar 20, 2018
    Posts:
    9
    @Kurt-Dekker Thank you for the answer.

    The reason I ask this question, is that I am working on implementing a script (from OPC UA if it helps) into a unity project.
    Code (CSharp):
    1. using Opc.Ua;   // Install-Package OPCFoundation.NetStandard.Opc.Ua
    2. using Opc.Ua.Client;
    3. using Opc.Ua.Configuration;
    Now I have all the dll files that the codes required, dragged and dropped them into Unity's assets folder, I also installed the NuGet package of OPCFoundation.NetStandard.Opc.Ua into the c# project that unity build for me, but I still get this error message:
    Unloading broken assembly Assets/Opc.Ua.Core.dll, this assembly can cause crashes in the runtime

    I tried to build the project, I got this error message:
    ArgumentException: The Assembly BouncyCastle.Crypto is referenced by Opc.Ua.Core ('Assets/Opc.Ua.Core.dll'). But the dll is not allowed to be included or could not be found.

    Then I put this BouncyCastle.Crypto.dll in assets' folder, and built it, it started to ask for Newtonsoft.Json, then Microsoft.AspNetCore.Http.Abstractions, the list kept going on. I gave up after importing 10 more dll files into unity.

    Do you know what is the reason/solution of this situation?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Are all of these modules .NET 2.0 subset compliant? (Or whatever version of .NET your version of Unity supports)
     
  5. YiHan-GI

    YiHan-GI

    Joined:
    Mar 20, 2018
    Posts:
    9
    I am using .Net 4.x.
    Anyway, I finally fixed these errors, by importing every dll file unity asked for, very patiently. So Unity wasn't fooling around :)
     
  6. vantknispel

    vantknispel

    Joined:
    Oct 28, 2018
    Posts:
    2
    Hi,I also get the same problem as you, I import all the OPC UA dll from OPCFoundation but it shows "Unloading broken assembly Assets/Plugins/OpcUaHelper/Opc.Ua.Configuration.dll, this assembly can cause crashes in the runtime". And I tried what you said, importing every dll file by "import new assert" into plugins folder, set scripting runtime version to .NET4.x, but it didn't work. Maybe there is something I did wrong?Thanks!
     
    Last edited: Nov 1, 2018