[RESOLVED] Console app check for DLL
This is my first time designing a console app, and I'm having difficulty in getting this to work. I want it to check for my DLL in the same directory. If it's not there, the application should exit gracefully.
I thought this code would work but it still crashes without the DLL. Although it will not crash if I comment out everything after the IF statement.
Code:
Imports MyDLL.Test
Module Module1
Sub Main()
If Not File.Exists("MyDLL.dll") Then
Console.WriteLine("MyDLL.dll is missing")
Console.ReadLine()
Exit Sub
End If
Re: Console app check for DLL
I don't see any code after the if block.
Re: Console app check for DLL
I left it off as it's all stuff using the dll. I was trying to get the application method to quit before it gets to that part if the dll isnt there
Re: Console app check for DLL
So you meant that you added a reference to "MyDLL.dll" in your project, but if the dll is not there, this will still run without throwing an exception?
Code:
Imports MyDLL.Test
Module Module1
Sub Main()
If Not File.Exists("MyDLL.dll") Then
Console.WriteLine("MyDLL.dll is missing")
Console.ReadLine()
Exit Sub
End If
End Sub
En Module
Re: Console app check for DLL
I'm pretty sure I haven't written this right. But ideally what I'd like is if the dll is not there, to just have the application say "Mydll.dll is missing" and exit after the user presses enter
Edit- And yes there is a reference to it in the project
Re: Console app check for DLL
As long as you don't have any code that uses the missing dll, your application will runs fine (it will work as shown in post#4 even if you added a reference to MyDLL.dll to the project and the dll is missing at run time). However, if you have just a single piece of code that uses the dll, even that code line never gets executed, you still get an exception. And that's why when you comment out the stuff below the if block it works.
To work around this, you will need to create a helper application that doesn't reference the dll and have that application as the startup exe. The helper will then check for the existence of the dll, and if it found the dll, it launches your main application. Otherwise, it displays a error message to the user.
Re: Console app check for DLL
Is it fully compiled and in a folder, like in Program Files or something?
Basically, how are you launching it? From the actual executable itself? From a shortcut link?
Re: Console app check for DLL
The program itself is just a single compiled exe. The bulk of the work is in the dll. For all practical purposes, the dll will always be there. But I want something that will tell the average user what went wrong in case I'm not there, should someone move it.
Is there a way to handle on the application level a FileNotFoundException?
Re: Console app check for DLL
The answer was much simplier than a helper application
Code:
Sub Main
If Not File.Exists("MyDLL.dll") Then
//Error code
Else
RestOfMain()
End If
End Sub
Sub RestOfMain
//My code
End Sub
Re: [RESOLVED] Console app check for DLL
oh duh...lol...
yh...u need an Else statement hahahahahaha