views:

57

answers:

2

I thought that latest Matlab does this automatically. I have tested the following exe on a clean Win XP VM:

namespace DotNetTest
{
    using System.Windows.Forms;

    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show("Howdy!");
        }
    }
}

When I run it on a computer which has all these installed, it does show the message box and a window. When I run it on a clean VM, I get this error:

Title: DotNetTest.exe - Application Error
Icon: Error
Buttons: {OK}
Message Body: The application failed to initialize properly (0xc0000135). Click on OK to terminate the application.

I would expect better from MSFT geniuses. Why cannot every .Net exe contain a tiny bit of overhead and have the very first bytes of it do the work of detecting if .Net is installed and presenting a better message.

Is there some sort of setting that I can flip to fix this? All of the settings were default ones provided by VS2010 when I created a new project.

Thank you.

+3  A: 

This is what you use an installer for. In .net this is simple, you just "publish" your project and you get an installer that makes shure that .net is installed and such. The application itself should never have to worry about that.

Alxandr
+1  A: 

As Alexandr says, you should really use the installer for this. If that's not possible, you'd have to write an unmanaged exe to run first and then either start the .net exe or tell the user to download the framework depending on if it's already installed.

ho1
The later option seems like a pain. I wish it was just given.
Hamish Grubijan
It's quite a pain, so unless you've got a specific reason I'd go with the standard way as in Alxandr's answer.
ho1
Thanks, ho1, do you know if there is an easier way?
Hamish Grubijan
@Hamish Grubijan: Sorry for the delayed answer, I missed your comment. No, you have to have some kind of unmanaged exe to run first (or if you're sure the users will always have .net 2.0 you could write an 2.0 exe that does it). The only other option I can think of would be to look into one of those tools that'supposedly includes all needed bits of the framework into your exe so that it would be self contained, but I don't know how well those works and you'd get problems with updates etc so I wouldn't recommend it.
ho1