views:

124

answers:

6

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.

+1  A: 

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.

Paja
+1  A: 

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.

rwmnau
It appears to be silently swallowing it. The network share thing doesn't appear to be an issue, depending on the client the user will get prompted that it is untrusted, but they are still able to launch it.
Nate Heinrich
.NET applications that are run from network shares have the same behavior as native applications by running with full trust since .NET 3.5 SP1, see http://blogs.msdn.com/brada/archive/2008/08/13/net-framework-3-5-sp1-allows-managed-code-to-be-launched-from-a-network-share.aspx
0xA3
A: 

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.

http://stackoverflow.com/questions/492967/is-there-a-dos-command-for-verifying-what-version-of-net-is-installed

MrGumbe
This is a good idea, I guess what I am really looking for, is why there is no error anywhere, it seems odd to me that the program would just fail silently.
Nate Heinrich
+7  A: 

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   
---------------------------
uncle brad
That works great!
Nate Heinrich
+1  A: 

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?
Joe White
+1 Thanks for the information. I didn't realize I would run into these issues by running off of a network share.
Nate Heinrich
A: 

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.

slugster