SucksAtAssembly
SucksAtAssembly

Reputation: 71

DLL cannot be found because the file name is different than the one referenced?

I have been baffled on how can this be happening.

So heres the deal, im trying to play a V2M chiptune with a dll called NV2.dll

Its referenced, and I used its functions like normal. BUT when i try to run the application i get

Unable to load DLL 'V2.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

The referenced DLL i used is called NV2, I have checked it, the assembly goes by NV2, not V2, why is it trying to load a dll with a different name?!

Upvotes: 0

Views: 117

Answers (1)

Maximilian Gerhardt
Maximilian Gerhardt

Reputation: 5353

So obviously, there is a reference to V2.dll inside the NV2.dll. Either the documentation is just shitty or you didn't notice that part, but inside the constructor of the NV2 class they try to write that V2.dll, which is saved inside the Resources of the dll as a byte[] V2 to disk, namely to the directory C:\Windows\system32. Code:

    public NV2()
    {
        List<WeakReference> _ENCList = NV2.__ENCList;
        Monitor.Enter(_ENCList);
        try
        {
            NV2.__ENCList.Add(new WeakReference(this));
        }
        finally
        {
            Monitor.Exit(_ENCList);
        }
        //Here comes the part that writes the resources
        FileStream fileStream = new FileStream(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.System), "\\V2.dll"), FileMode.OpenOrCreate);
        fileStream.Write(Resources.V2, 0, checked((int)Resources.V2.Length));
        fileStream.Close();
    }

Meaning that either in your application you first have to do a

  var engine = new NV2(); //triggers the constructor code

to trigger that, or you go hardcore on that and dump the byte[] from their dll.

I've dumped that file here for you and zipped it: http://www.file-upload.net/download-11263190/V2.zip.html

(You could have done that by saving the project using teleriks decompiler, fixing the errors in the ressources, changing the project to a console project, then coding a Main function like)

using System.IO;
using NV2.My.Resources;

namespace NV2
{
    class MainClass
    {
        static void Main(string[] args)
        {
            FileStream fileStream = new FileStream("V2.dll", FileMode.OpenOrCreate);
            fileStream.Write(Resources.V2, 0, checked((int)Resources.V2.Length));
            fileStream.Close();
        }
    }
}

Upvotes: 1

Related Questions