Give to my program the possibility to detect if one of required assemblies is not found
-
Hello ! I'm creating a program in vb.net 2013 , that use a lot's of assemblies. what code should I use , in order that during the program startup , to test if one of these assemblies is missing or corrupted , and if yes to display an appropriate message to the user , and after to close the program. ( Because actually , if this happen my program display a large message and hang , and I should close with task manager , and I don't like this ) Thank you !
-
Hello ! I'm creating a program in vb.net 2013 , that use a lot's of assemblies. what code should I use , in order that during the program startup , to test if one of these assemblies is missing or corrupted , and if yes to display an appropriate message to the user , and after to close the program. ( Because actually , if this happen my program display a large message and hang , and I should close with task manager , and I don't like this ) Thank you !
You normally don't do this. The Program Files folder and everything under it is ReadOnly to normal users. There's no way for the users to corrupt or delete the files. Something similar to this is normally left up to the Windows Installer to figure out. If a component is missing, the Installer puts it back when the app is run. Of course, your installer has to be setup to support this. Now, if you're giving users administrative permissions, you're screwing yourself by letting users message with stuff they shouldn't be.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
You normally don't do this. The Program Files folder and everything under it is ReadOnly to normal users. There's no way for the users to corrupt or delete the files. Something similar to this is normally left up to the Windows Installer to figure out. If a component is missing, the Installer puts it back when the app is run. Of course, your installer has to be setup to support this. Now, if you're giving users administrative permissions, you're screwing yourself by letting users message with stuff they shouldn't be.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
And? That doesn't change the fact that the installer should cover this, not your code. You won't have the opportunity to detect and/or fix every assembly from your code.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Hello ! I'm creating a program in vb.net 2013 , that use a lot's of assemblies. what code should I use , in order that during the program startup , to test if one of these assemblies is missing or corrupted , and if yes to display an appropriate message to the user , and after to close the program. ( Because actually , if this happen my program display a large message and hang , and I should close with task manager , and I don't like this ) Thank you !
You've got lots of automatic code-checking in the IDE with the references. If you stopped autoloading them and loaded everything using reflection, you'd loose quite some benefits and performance. Create a "loader"-application; one without any UI at all, that simply checks if all the files mentioned in a text-file are still in the expected locations (and, if you're paranoid, the date of creation, modification and last known hashcode). If all is as expected,
Proces
.Start your application and exit the loader. Works better if your users cannot start the main-application directly. There's multiple tricks that you could use to ensure that only the loader-application is used to start your main-executable, like passing a hash of a combination of a known guid and the current date and having the main-app exit if that is incorrect. If your end-users have administrator-rights, then they can still simply download ILSpy[^] and build their own damn loader :)Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
You've got lots of automatic code-checking in the IDE with the references. If you stopped autoloading them and loaded everything using reflection, you'd loose quite some benefits and performance. Create a "loader"-application; one without any UI at all, that simply checks if all the files mentioned in a text-file are still in the expected locations (and, if you're paranoid, the date of creation, modification and last known hashcode). If all is as expected,
Proces
.Start your application and exit the loader. Works better if your users cannot start the main-application directly. There's multiple tricks that you could use to ensure that only the loader-application is used to start your main-executable, like passing a hash of a combination of a known guid and the current date and having the main-app exit if that is incorrect. If your end-users have administrator-rights, then they can still simply download ILSpy[^] and build their own damn loader :)Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
Sorry Friends ! Why you don't just try to answer to my question instead of telling me that what I want to do is wrong ? If my question has an answer , please help me to find. About the response , I read somewhere about Appdomain.UnhandledException , AppDomain.FirstChanceException and AppDomain.AssemblyResolve. But I'm not sure what should I do . Can you give me a suggestion ? Thank you !
-
Sorry Friends ! Why you don't just try to answer to my question instead of telling me that what I want to do is wrong ? If my question has an answer , please help me to find. About the response , I read somewhere about Appdomain.UnhandledException , AppDomain.FirstChanceException and AppDomain.AssemblyResolve. But I'm not sure what should I do . Can you give me a suggestion ? Thank you !
-
Sorry Friends ! Why you don't just try to answer to my question instead of telling me that what I want to do is wrong ? If my question has an answer , please help me to find. About the response , I read somewhere about Appdomain.UnhandledException , AppDomain.FirstChanceException and AppDomain.AssemblyResolve. But I'm not sure what should I do . Can you give me a suggestion ? Thank you !
dilkonika wrote:
Why you don't just try to answer to my question
I did. You did not mention the AppDomain in your original question. The approach would have been correct for most scenario's, and you could simply show your messagebox. As a warning, I'm not going to post 20 answers in this thread. I just implemented it, using MSDN[^]. Not very useful. You can only recover if you have the full assembly. If it was there, then it should have already been found. You could only recover if you had all assemblies "twice" on the system, loading them from another location. ..and your users could have deleted them there too, so you just moved your problem to another location, while also doubling the space required.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
Sorry Friends ! Why you don't just try to answer to my question instead of telling me that what I want to do is wrong ? If my question has an answer , please help me to find. About the response , I read somewhere about Appdomain.UnhandledException , AppDomain.FirstChanceException and AppDomain.AssemblyResolve. But I'm not sure what should I do . Can you give me a suggestion ? Thank you !
There is no real solution to the problem. The problem is not how your code can recover. It's that fact that if an admin screws up the app THEY are responsible for fixing it, not you.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
There is no real solution to the problem. The problem is not how your code can recover. It's that fact that if an admin screws up the app THEY are responsible for fixing it, not you.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
I understand that. but I don't want that my application in a such scenario to hang and to be difficult to close it. and of course I want a good messaging behavior to inform the user about what is happening.
dilkonika wrote:
but I don't want that my application in a such scenario to hang and to be difficult to close it. and of course I want a good messaging behavior to inform the user about what is happening.
That is done using a loader, as explained. I've used the principle before, for an app that needed certification and one of the requirements was to ensure that the files were "as expected". It should recognize "any tampering". Easy with a loader and some hashing.
dilkonika wrote:
About the response , I read somewhere about
If you're only interested in a single kind of solution, please add it to the starting-post. If possible, with a hyperlink! Now, since you're not going to change your mind even if I say you cannot guarantee that your backups are not equally corrupted, here's your personalized example;
- Create a NEW solution, add a console-project
- Add a class-library and call it "ClassLibrary1".
Edit the class in the classlibrary to look like below;
namespace ClassLibrary1
{
public static class Class1
{
public static string Property1 { get { return "Hello From Class1"; } }
}
}Go to the console-app, and change the Program.cs to below;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += currentAppDomain_AssemblyResolve;externalTest(); Console.ReadLine(); } static System.Reflection.Assembly currentAppDomain\_AssemblyResolve(object sender, ResolveEventArgs args) { Console.WriteLine("Assembly Resolve {0}", args.Name); return AppDomain.CurrentDomain.Load(File.ReadAllBytes(@"D:\\Projects\\ConsoleApplication8\\ClassLibrary1\\bin\\Debug\\Copy of ClassLibrary1.dll")); } static void externalTest() { Console.WriteLine(ClassLibrary1.Class1.Property1); } }
}
- Change the path in the above code to your own local folder.
- Put a reference from the Console-app to ClassLibrary1.
- Build.
- Make a copy of the file "ClassLibrary1.dll", rename it to "Copy of ClassLibrary1.dll" (but keep it in that folder, otherwise you'd need to rebuild to update the folder-location in the code)
- Remove the file "ClassLibrary1.dll" from the debug-folders from BOTH pr