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.