Import dll in notepad++ plugin

2013-05-03
2013-05-06
  • lkachun9129

    lkachun9129 - 2013-05-03

    Hi all,

    I am making a plugin which requires another dll (both written in C#).

    However, it seems that just putting the two dll together inside "Plugins" folder is not the solution. It gives error on dll not found. Anyone knows the solution?

    Error Details:
    Could not load file or assembly 'xxxxxx, Version=...' or one of its dependencies. The system cannot find the file specified.

    Thanks and regards,
    Ronald

     
  • pedro_sland

    pedro_sland - 2013-05-03

    I'm not very good with these sort of things but I'm reasonably sure the extra dll has to be in the same folder as n++.

    I take it you're using the c# template or something because I really don't think n++ can use regular c# dlls. If you weren't I don't think you'd be getting that error.

     
  • CorruptedFile

    CorruptedFile - 2013-05-05

    The default location that N++ seems to search for the second dll is in the N++ install directory. I am using the NppPlugin.NET.v0.6 template and had the same issue. I added the following code to the UnmanagedExports class in the UnamanagedExports.cs and it solved my issue.

    ~~~~~~~~~
    :::C#
    static UnmanagedExports()
    {
    AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve;
    }

    static Assembly OnCurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
    {
    if (args.Name.Contains("<NAME OF="" DLL="" TO="" BE="" LOADED="">"))
    {
    var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    return Assembly.LoadFile(Path.Combine(location, @"<RELATIVE PATH TO DLL TO BE LOADED"));
    }
    }
    ~~~~~~~~~~

    The "NAME OF DLL TO BE LOADED" should not contain the extension. The relative path starts from the plugins folder of N++. I.e. if your 2nd dll is in the plugins folder then it would be "2nd.dll", but if you have a folder within the plugins that contains your 2nd dll, then it would be "FolderName\2nd.dll"

    Hope this helps.
    Disclaimer: I am very much a beginner at programming in C++ and C# myself, but the above is working flawlessly for my plugin.

     
    Last edit: CorruptedFile 2013-05-05
    • lkachun9129

      lkachun9129 - 2013-05-06

      Yeah!!! it works!!! Thank you so much :D

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks