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

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:

using UnityEngine;
using System.Collections;
using System;
using nddsdotnet;

public class PruebaDDS : MonoBehaviour {

    // Use this for initialization
    void Start () {
  
        // Create the DDS Domain participant on domain ID 0
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                0,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null, /* Listener */
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null) {
            Console.Error.WriteLine("Unable to create DDS domain participant");
            return;
        }

    }

    // Update is called once per frame
    void Update () {

    }
}

To resolve the error I read this part of the Unity’s manual: Unity - Manual: Managed plug-ins
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.

Check if that dll is compiled against .NET 3.5.

Ok, the DLL is compiled against .NET 2.0

.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” ?

I can’t find that option in Unity (I think that it’s only available in Unity 5, and I am using Unity 4…).

Oh, then you probably need to place that dll in Assets\Plugins folder.

The DLL is already in Assets\Plugins folder, but I still get the error.

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.

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?

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:

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 :0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in :0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in :0
at Mono.CSharp.Driver.Compile () [0x00000] in :0
at Mono.CSharp.Driver.Main (System.String[ ] args) [0x00000] in :0

Up

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.

Ok, thank you very much for your help.

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. :slight_smile:

1 Like

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 :).

i had the same problem.it was because the Plugins folder should has the exact name “Plugins”