eba
eba

Reputation: 979

.net dll dependencies checking

i have small winforms application, which uses about 20 external dlls. how can i check for all their existance, while application initializing? to say:"u dont have some dll, install it corrctly".

Upvotes: 1

Views: 357

Answers (3)

klm_
klm_

Reputation: 1209

You have to loop through all custom types (using reflections) used in your application and try to create an instance of each of them. Of course in try/catch. Then have a catch on FileNotFoundException and inform the user there if some libs are missing.

When you create instance of types used in your application AppDomain loads needed libs (so it will throw exception if file is not found).

I think that will help.

Upvotes: 1

Tim Barrass
Tim Barrass

Reputation: 4939

If you use a plugin-style architecture then you can resolve all your dependencies late -- on demand even -- and you can take control of what happens if a dependency can't be resolved.

It doesn't need to be complicated -- see for example this simple approach.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

If one of the required assemblies are missing your application might not even be loaded by the CLR. So you could write a loader application which will do the job of checking the existence of the required assemblies and if they exist Process.Start the main application.

Upvotes: 0

Related Questions