Why isn't an exception thrown when the right .NET framework version is not present?
We have a .NET application which targets .NET 3.5. Our clients run it from a shared drive (very infrequently) in order to have a central config file location.
We have noticed that if a workstation accesses the shared drive and runs the program, but does not have .NET 3.5 installed, nothing happens, no error, no exception, no log entry, it just doesn't launch.
Why is there no error message shown in windows by the CLR?
Is there something I can put at the beginning of the code that would ensure that a proper error message is displayed?
It is not an option to run an installer that would check for prereqs, as we are only installing it in one central location.
Thanks.
Ideally, we wouldn't have to have a wrapper to query for the .NET version, it seems that the program is failing to launch, and windows should be reporting this somewhere. I can't believe it would just silently fail. 开发者_JAVA百科
Try something like this you app.config;
<configuration>
<startup>
<supportedRuntime version="v3.5" />
</startup>
</configuration>
I get a nice little dialog, like so;
--------------------------- moreverfoo.exe - .NET Framework Initialization Error --------------------------- To run this application, you first must install one of the following versions of the .NET Framework: v3.5 Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework. --------------------------- OK ---------------------------
Well I guess you can create app in C++, which will check if the required .NET is installed. If not, display your messagebox, and if it is installed, the app will run the program you need from shared drive.
Are there any entries in the event logs when the application doesn't launch? It's hard to believe, though I suppose not impossible, that it would fail completely silently. Perhaps your application is actually generating an exception before the first form is loaded, silently swallowing it (empty catch block) and then quitting, all without any kind of logging or error message.
Also, you normally can't run .NET applications over a network share because it's an "untrusted location", and I've always gotten a security exception in the past.
If a machine has .NET 3.5 SP1 installed (as your development machine probably does), then you can run a .NET app from a network share, and it will run normally, with full trust. But this is new in 3.5 SP1 -- it wasn't even true in the original 3.5 release. Prior to 3.5 SP1, if you try to run an app from a network share, it will run with restricted permissions.
Since these machines don't have 3.5, it's a sure bet they don't have 3.5 SP1. So your app won't be able to do things like open files, or P/Invoke to unmanaged code. If it tries, you'll get security exceptions.
- What happens when you copy the EXE to the local hard drive on these machines, and run it from there?
- What happens if your app gets security exceptions at startup? Is your own code masking the exception somehow?
Instead of posting the executable directly, you could create a batch file that first checks to see if the correct version of .NET is installed (see link below) and either launch the app and close the console window, or display an error message and pause.
Is there a command line command for verifying what version of .NET is installed
To specifically answer your questions:
No. Ask yourself this question: if the required level of the framework is not present, what version of the CLR should be allowed (or made to) to show the error message?
Also no. There is no unmanaged bit of code/stub that runs at the start of your app before it becomes managed, so no way to pre-emptively check for the correct version of the framework.
So a bootstrapper or wrapper is your only option - or you could look at a click once type of application, and see if you can enforce the prerequisite (of the right framework) using that.
精彩评论