0

So I've been using the NAudio.dll in my VB.Net project and so far it was quite easy using it by utilizing Imports NAudio.Wave and just calling the one class and function I need from that class.

Now it works flawlessly in my project and it is added as a ressource in my project.

But whenever I deploy my project and try to run it outside of Visual Studio it throws something along the lines of

System.IO.FileNotFoundException - The File or Assembly "NAudio, Version=1.10.0.0, Culture=neutral, PublicKeyToken=null" was not found [...]

So now when I add the already in my project included DLL to the output folder in the same directory where my deployed application lies, it has no problems and "finds" the DLL and class and functions. What I've found out up to now is that there are managed and unmanaged DLL, meaning DLLs from the .Net framework and "normal" other DLLs with machine code. Also, there seem to be static and dynamic DLLs which are implemented in different ways.

As far as I know, the NAudio.dll is a dynamic, managed code DLL. Thats why I can call the functions and classes in my code with using Imports .... But because it's not a static library, I am not able to just compile it into my source code and use it in a standalone application.

I tried to decompile and recompile it to a static DLL with a tool, but it seems that it failed at a certain point when trying it and thus I was not able to successfully do that.

Also, I tried to make a DLL import with the System.Runtime.InteropServices along the lines like this

 <DllImport("NAudio.DLL")>
        Private Class WaveFileReader
        End Class

but ultimately didn't understand how to import a class and its needed functions.

The actual only critical code that I use where the NAudio.dll is utilized is this section:

Public Function ExtractWavFileDuration(ByVal AudioFile As String) As System.Timers.Timer
            If CustomSoundHelper.IsSystemSoundFile(AudioFile) Then Return New System.Timers.Timer(StandardSystemSoundLength)

            ' Get duration of wave file
            Dim duration As TimeSpan
            Using fileStream As New IO.FileStream(AudioFile, IO.FileMode.Open)
                Using reader As New WaveFileReader(fileStream)
                    duration = reader.TotalTime
                End Using
            End Using
            ' Create Timer
            Dim t As New Timers.Timer(duration.TotalMilliseconds)
            Return t
        End Function

where I use the Wavefilereader class.

So my ultimate question is:

Are my assumptions correct, and if not, what am I missing? And how can I achieve that I use the NAudio.dll in my code easily, refer to it and use it's classes/functions, etc., while not having to include it in the application output directory and thus can create a standalone application with the DLL?

Update: I found that one can embed a DLL as resource and then load the DLL from the Assembly. Unfortunately I wasn't able to do this yet, because the IO.FileNotFoundException wouldn't be catched. Im on it, though.

Vandrey
  • 531
  • 1
  • 8
  • 23
  • And how do I register the DLL? – Vandrey Feb 01 '21 at 12:46
  • "it is added as a ressource in my project", that doesn't sound good. NAudio.dll must get copied into your project's bin\Release directory, along with your .exe file. Deploy *both* files to another machine. – Hans Passant Feb 01 '21 at 13:25
  • @HansPassant Yeah but exactly that is what I want to avoid. I want a standalone application without any output dependencies. – Vandrey Feb 01 '21 at 16:23
  • @jdweng I have a 64-bit application – Vandrey Feb 01 '21 at 16:23
  • Look at Liam answer : https://stackoverflow.com/questions/4897685/how-do-i-register-a-dll-file-on-windows-7-64-bit – jdweng Feb 01 '21 at 19:25
  • But then I still have to ship the DLL with the software and manually register the DLLs in the target machines, right? Thats somehow weird, since it should also run on Linux. – Vandrey Feb 02 '21 at 11:35

0 Answers0