Aommaster
Aommaster

Reputation: 125

Check Project Dependencies

I have a VB.Net project with a number of my own written class libraries, which are set as dependencies to my program.

What I would like to do is check to see if the respective DLL's exist in the application's folder, before it goes through its startup routine. In short, the startup routine reads from a serialized database file into an object. This object is then used all around the program for various forms of data-storage. What I found was if a dependency was accidentally deleted, the program would start and generate the unhandled exception error. If you pressed "quit" the program would terminate, but it would also corrupt the serialized database file. I'd like to prevent this by doing a check to see if the file exists. If the file doesn't exist, it would notify you, and pressing okay would terminate the project, but in a safe way as to not corrupt the database.

I was able to find something like this but this seems to just be an external dll file. My project actually has sub-projects which generate each file.

I have a feeling it's not possible, because rather than an external dll, the dll's are actually used for the program. It won't be able to run without them, and hence, won't be able to execute code without them. However, I'd like to just make sure with someone that is more experienced than I am.

Edit: One way I could see doing it is to have a "launcher"-type of program. This file will check if all the files exist, and only if they do, the main executable would be run. However, I'd like to try and avoid having multiple exe's if at all possible.

Upvotes: 1

Views: 1239

Answers (1)

If Form Load code results in references to these externals, change the project to start from a sub Main: Project Properties -> Application -> StartUp Object -> Sub Main

Add a module, and a sub main (or add a Sub main to an existing module):

Public Sub Main()
    ' check for file exist on list of files here

    ' turn on styles
    Application.EnableVisualStyles()

    ' start message pump
    Application.Run(New frmMain)         ' use your form name
                                    ' the form load will run at this point
End Sub

Presumably, you'd show what files are missing in a messagebox or something and exit. This would be useful if a class library included a control that was used on the form - you could test for it before the form is created. Frankly users that poke around and delete files get what they deserve.

Upvotes: 1

Related Questions