mcnamaragio

Let's say I have an application written in c# which references custom dll. If that dll file is not found then when launching the application it will hang and display "Send, Don't Send" message. Is there any way override this message and display my custom message with more explanations. So the application has to check if that dll file exists.


Re: Visual C# General how to check referenced dll existence

utkuozan

You should either use try-catch blocks or check the existance of file at the starting point. Use of try-catch block is clearly explained in MSDN so I won't write about it but if you would like to use file checking you should:

1) Open "AppInit.cs" file

2) Add reference to "System.IO" at the using block (using System.IOWink

3) Add reference to "Windows.Forms" if necessary at the using block (using System.Windows.FormsWink

4) at the Main() block you should code

if (File.Exists(filePath))

{

Application.Run(new StartForm);

}

else

{

MessageBox.Show("File not found");

}

That should work out for you.

PS: filePath is the string type variable holding your file's complete path & StartForm is the name of the class that your main form is defined in.






Re: Visual C# General how to check referenced dll existence

TilakGopi

Hi,

Let us suppose cp is the component class u r using the from thelibrary, then the following code will let u know whether the dll exists or not.

Add System.Reflection name space to the project.


//Trimming file:///

string strDllPath = Assembly.GetAssembly(cp.GetType()).CodeBase.Substring(8);
if (File.Exists(strDllPath))
Console.WriteLine("Assembly dll exists ");
else

Console.WriteLine("doesn't exist");

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C# General how to check referenced dll existence

mcnamaragio

Thanks for your reply. Will the application be able to initialize to check the existence of the referenced dll file is uses




Re: Visual C# General how to check referenced dll existence

utkuozan

Well, haven't tried the code myself but since it runs before the initial run hope it does




Re: Visual C# General how to check referenced dll existence

TilakGopi

Thanks for your reply. Will the application be able to initialize to check the existence of the referenced dll file is uses

mcnamaragio ,


My code is working fine,so for ur question ,answer is yes,AFAIK.

Utku Ozan,

to remove the smile symbols have spece between character and :: .

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C# General how to check referenced dll existence

mcnamaragio

I have got one more question. If the dll file exists and it needs to be registered but it isn't then the application will throw the same error. Can the program check if the dll is registered. If not register it by using regsvr32 and if the registration succeeds, then continue working. Thanks




Re: Visual C# General how to check referenced dll existence

Peter Ritchie

There's nothing you can do in code. That error is displayed when the framework is loading your application; it can't find the referenced DLLs and doesn't load your application. Suggestions for exception handling or reflection simply won't work because that code will never run.

If you have DLLs that you want to load at runtime you'll have to load them manually and not directly reference any types within those DLLs. Otherwise, include those DLLs with your application.




Re: Visual C# General how to check referenced dll existence

Peter Ritchie

TilakGopi, there is a Quote button you should use to quote another message. If you use that button it's far more clear you're quoting someone else.




Re: Visual C# General how to check referenced dll existence

TilakGopi

Hi Peter,

I did it in someway.Is this the way you suggested me see my last but one reply.

Thanks&Best Regards,

Ch.T.Gopi Kumar.






Re: Visual C# General how to check referenced dll existence

TilakGopi

mcnamaragio wrote:
I have got one more question. If the dll file exists and it needs to be registered but it isn't then the application will throw the same error. Can the program check if the dll is registered. If not register it by using regsvr32 and if the registration succeeds, then continue working. Thanks

Hi mcnamaragio,

I'm not getting the way ,

better post the above question in a new thread to get answered.

Thanks,

Ch.T.Gopi Kumar.