Search Unity

Problem with external DLL (error CS0246: missing type or namespace...)

Discussion in 'Editor & General Support' started by SoryRules, Apr 7, 2015.

  1. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    Hi all,

    English isn't my first language so I will do my best to explain to you.

    I want to import an external DLL to my project (a third-party DLL) but when I try to import it, my DLL doesn't appear between the options in the folder. For this reason I copied the DLL directly in the Assets folder. However, when I create a script and I use this DLL I get this error:

    Assets/PruebaDDS.cs(4,7): error CS0246: The type or namespace name `nddsdotnet' could not be found. Are you missing a using directive or an assembly reference?

    I have put the using directive ("using nddsdotnet"), the DLL is in the Asset folder and in the References of MonoDev, so what could be the error?

    This is my code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. using nddsdotnet;
    5.  
    6. public class PruebaDDS : MonoBehaviour {
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.  
    11.         // Create the DDS Domain participant on domain ID 0
    12.         DDS.DomainParticipant participant =
    13.             DDS.DomainParticipantFactory.get_instance().create_participant(
    14.                 0,
    15.                 DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
    16.                 null, /* Listener */
    17.                 DDS.StatusMask.STATUS_MASK_NONE);
    18.         if (participant == null) {
    19.             Console.Error.WriteLine("Unable to create DDS domain participant");
    20.             return;
    21.         }
    22.  
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update () {
    27.  
    28.     }
    29. }
    To resolve the error I read this part of the Unity's manual: http://docs.unity3d.com/Manual/UsingDLL.html
    especifically this paragraph:

    To create a DLL, you will first need a suitable compiler. Not all compilers that produce .NET code are guaranteed to work with Unity, so it may be wise to test the compiler with some available code before doing significant work with it.

    Maybe my DLL isn't compatible with Unity? I really appreciate any help you can provide.
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    Check if that dll is compiled against .NET 3.5.
     
  3. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    Ok, the DLL is compiled against .NET 2.0
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    .NET 2.0 should be also good, ok then another question, when you click on the plugin in the Unity is it marked as compatible with "Any Platform" or "Editor" ?
     
  5. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    I can't find that option in Unity (I think that it's only available in Unity 5, and I am using Unity 4...).
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    Oh, then you probably need to place that dll in Assets\Plugins folder.
     
  7. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    The DLL is already in Assets\Plugins folder, but I still get the error.
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    Without a repro it's really hard to say... maybe you're simply using API incorrectly, download ilspy.net, drag that assembly on to it, and see what API is available.
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    It's also possible the assembly isn't loading because it depends on other assembly references that aren't available. Where did this assembly come from?
     
  10. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    I don't understand very well your question (I'm a beginner with these things).

    The DLL I'm using it's an external DLL from RTI (https://www.rti.com/). Here a link to download the DLL: https://dl.dropboxusercontent.com/u/77961300/nddsdotnet.dll.
    This is I get when I use ILSpy over the DLL:
    upload_2015-4-9_11-46-53.png


    By the way I've updated Unity (to Unity 5.0) and now I get this error:


    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

     
    Last edited: Apr 9, 2015
  11. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
  12. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    I opened that dll with ILSpy, and there's no nddsdotnet namespace there, so the error regarding "using nddsdotnet" is a valid one.

    Also, it seems, this dll was compiled from C++ with CLR support. I don't think it's possible to use it in Unity. In Unity you can only use pure managed dlls.
     
  13. SoryRules

    SoryRules

    Joined:
    Apr 7, 2015
    Posts:
    7
    Ok, thank you very much for your help.
     
  14. IMD

    IMD

    Joined:
    Mar 21, 2013
    Posts:
    14
    Hello all another cause of this, may be that the Unity Import Settings for your custom DLL are not configured correctly.This can happen if your Unity Editor platform is set to something not checked in these settings. As an example my dll in was not being fully accessed as I was excluding Win builds.

    To check these, simply select your dll in the Unity project and check the inspector tab.

    Hope that may help some people. :)
     
    newhook likes this.
  15. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    2018 ... hit this bug in Unity again ... but of course, the folks at Unity have removed the many-years-old workaround/fix "re-sync with monodevelop project".

    Quitting and restarting had the same effect. But I'd rather they hadn't removed the menu option, since it worked, and is apparently still needed :).
     
  16. viktorkadza

    viktorkadza

    Joined:
    Sep 4, 2018
    Posts:
    46
    i had the same problem.it was because the Plugins folder should has the exact name "Plugins"