Downlevel .NET question
Downlevel .NET question
posted by MC at 07/24/2008 08:00PM
..NET 2.0? Does the user get a meaningful error message?
posted by Duggi at 07/24/2008 11:20PM
wrote:
What happens if a .NET 3.5 .exe file is executed on a computer that only has
.NET 2.0? Does the user get a meaningful error message?
To my surprise, one .exe created with express edition using 3.5, ran
successfully on a machine having framework 2.0. I was expecting an
error....
-Cnu
posted by Pavel Minaev at 07/24/2008 11:21PM
wrote:
What happens if a .NET 3.5 .exe file is executed on a computer that only has
.NET 2.0? Does the user get a meaningful error message?
There is no such thing as a ".NET 3.5 .exe file" - any assembly you
build targeting .NET 3.5 is binary compatible with .NET 2.0 (because
both use the same 2.0 runtime). The only difference may be that .NET
3.5 assembly can reference some of the new assemblies from 3.5. In
this case, and if you actually try to use anything from those
referenced assemblies, you'll get the exact same error as for a
missing library. If you do not use any 3.5 assemblies, it will just
run.
Note that you can register your own handler for
AppDomain.AssemblyResolve event to detect missing assemblies and
provide your own error message if the assembly is a 3.5 one.
posted by Jon Skeet [C# MVP] at 07/25/2008 07:33AM
wrote:
<snip>
There is no such thing as a ".NET 3.5 .exe file" - any assembly you
build targeting .NET 3.5 is binary compatible with .NET 2.0 (because
both use the same 2.0 runtime). The only difference may be that .NET
3.5 assembly can reference some of the new assemblies from 3.5. In
this case, and if you actually try to use anything from those
referenced assemblies, you'll get the exact same error as for a
missing library. If you do not use any 3.5 assemblies, it will just
run.
Not quite. The other possibility is that you might have referenced one
of the .NET 2.0 SP1 classes in existing assemblies - things like
DateTimeOffset. Those will exist on a .NET 2.0SP1 installation, but
not vanilla .NET 2.0.
Jon
posted by MC at 07/25/2008 08:01AM
"Pavel Minaev" <int19h@gmail.com> wrote in message
news:a310ff45-8f61-4876-8f5e-9857c624ab7f@r35g2000prm.googlegroups.com...
wrote:
--------------
There is no such thing as a ".NET 3.5 .exe file" - any assembly you
build targeting .NET 3.5 is binary compatible with .NET 2.0 (because
both use the same 2.0 runtime). The only difference may be that .NET
3.5 assembly can reference some of the new assemblies from 3.5. In
this case, and if you actually try to use anything from those
referenced assemblies, you'll get the exact same error as for a
missing library. If you do not use any 3.5 assemblies, it will just
run.
-------------
Thanks. What are the new assemblies?
re: Downlevel .NET question
news:a310ff45-8f61-4876-8f5e-9857c624ab7f@r35g2000prm.googlegroups.com...
wrote:
--------------
What happens if a .NET 3.5 .exe file is executed on a computer that only
has
.NET 2.0? Does the user get a meaningful error message?
There is no such thing as a ".NET 3.5 .exe file" - any assembly you
build targeting .NET 3.5 is binary compatible with .NET 2.0 (because
both use the same 2.0 runtime). The only difference may be that .NET
3.5 assembly can reference some of the new assemblies from 3.5. In
this case, and if you actually try to use anything from those
referenced assemblies, you'll get the exact same error as for a
missing library. If you do not use any 3.5 assemblies, it will just
run.
-------------
Thanks. What are the new assemblies?
posted by Pavel Minaev at 07/25/2008 03:30PM
On Jul 25, 6:33 pm, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
I stand corrected - got bitten by that myself another day, only in my
case it was INotifyPropertyChanging.
But then again, 2.0SP1 is technically still 2.0, and it's available as
a separate download (and installs on all platforms vanilla 2.0 worked
on).
On a side note, I wonder why VS2008 Setup Project uses plain 2.0 and
not 2.0SP1 redistributable if you ask to include the dependencies with
the installer...
re: Downlevel .NET question
Not quite. The other possibility is that you might have referenced one
of the .NET 2.0 SP1 classes in existing assemblies - things like
DateTimeOffset. Those will exist on a .NET 2.0SP1 installation, but
not vanilla .NET 2.0.
I stand corrected - got bitten by that myself another day, only in my
case it was INotifyPropertyChanging.
But then again, 2.0SP1 is technically still 2.0, and it's available as
a separate download (and installs on all platforms vanilla 2.0 worked
on).
On a side note, I wonder why VS2008 Setup Project uses plain 2.0 and
not 2.0SP1 redistributable if you ask to include the dependencies with
the installer...
posted by MC at 07/28/2008 10:01AM
What happens if a .NET 3.5 .exe file is executed on a computer that only
has .NET 2.0? Does the user get a meaningful error message?
Here's an answer.
An .EXE targeted for .NET 3.5 will not run on a freshly installed Vista
machine (which I thought would have .NET 3.0). Nor does it give a
meaningful error message to the user. All you get is "So-and-so has stopped
working" and, in the log, an Event 1001, event name CLR20r3, P4=mscorlib,
P5=2.0.0.0.
Not convenient.
posted by Jon Skeet [C# MVP] at 07/28/2008 10:01AM
MC <for.address.look@www.ai.uga.edu.slash.mc> wrote:
Well, it will do that in some cases - like if you use a type declared
in .NET 2.0 SP1 or .NET 3.0 SP1, or reference a .NET 3.5 assembly.
If you don't use anything that's not in .NET 2.0 (or 3.0 for Vista) is
should work fine.
--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.pobox.com/
C# in Depth: http://www.pobox.com/
re: Downlevel .NET question
What happens if a .NET 3.5 .exe file is executed on a computer that only
has .NET 2.0? Does the user get a meaningful error message?
Here's an answer.
An .EXE targeted for .NET 3.5 will not run on a freshly installed Vista
machine (which I thought would have .NET 3.0). Nor does it give a
meaningful error message to the user. All you get is "So-and-so has stopped
working" and, in the log, an Event 1001, event name CLR20r3, P4=mscorlib,
P5=2.0.0.0.
Not convenient.
Well, it will do that in some cases - like if you use a type declared
in .NET 2.0 SP1 or .NET 3.0 SP1, or reference a .NET 3.5 assembly.
If you don't use anything that's not in .NET 2.0 (or 3.0 for Vista) is
should work fine.
--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.pobox.com/
C# in Depth: http://www.pobox.com/
posted by MC at 07/28/2008 10:01AM
An .EXE targeted for .NET 3.5 will not run on a freshly installed Vista
machine (which I thought would have .NET 3.0). Nor does it give a
meaningful error message to the user. All you get is "So-and-so has
stopped
working" and, in the log, an Event 1001, event name CLR20r3, P4=mscorlib,
P5=2.0.0.0.
Not convenient.
Well, it will do that in some cases - like if you use a type declared
in .NET 2.0 SP1 or .NET 3.0 SP1, or reference a .NET 3.5 assembly.
If you don't use anything that's not in .NET 2.0 (or 3.0 for Vista) is
should work fine.
Is there anything I can put in my program to trap this condition and give a
more useful error message? Or is the failure occurring as the program
loads, before it tries to execute?
In my case, the program uses an extension method, and that seems to be what
trips it.
posted by Jon Skeet [C# MVP] at 07/28/2008 02:01PM
MC <for.address.look@www.ai.uga.edu.slash.mc> wrote:
Yes, there weren't any extension methods (or even the attribute) in
..NET 3.0.
--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.pobox.com/
C# in Depth: http://www.pobox.com/
re: Downlevel .NET question
Well, it will do that in some cases - like if you use a type declared
in .NET 2.0 SP1 or .NET 3.0 SP1, or reference a .NET 3.5 assembly.
If you don't use anything that's not in .NET 2.0 (or 3.0 for Vista) is
should work fine.
Is there anything I can put in my program to trap this condition and give a
more useful error message?
[/quote:1f7ecc3398]
Not easily, as far as I know.
[quote:1f7ecc3398]Or is the failure occurring as the program loads, before it tries to execute?
[/quote:1f7ecc3398]
I don't know, to be honest. I suggest you try it and see - try to write
code that calls a method in .NET 3.5, and see if you can get it to
execute at all.
My *guess* is that when the class that refers to a .NET 3.5 class is
first initialized, that's when it'll first go bang - but it could be at
the method level, or the whole assembly level...
[quote:1f7ecc3398]In my case, the program uses an extension method, and that seems to be what
trips it.
Yes, there weren't any extension methods (or even the attribute) in
..NET 3.0.
--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.pobox.com/
C# in Depth: http://www.pobox.com/
posted by Pavel Minaev at 07/29/2008 10:25AM
On Jul 28, 8:22 pm, "MC" <for.address.l...@www.ai.uga.edu.slash.mc>
wrote:
Since an extension method translates to an instance of
ExtensionAttribute, and since attributes are (so far as I know)
instantiated when assembly is loaded, it would seem that you can't
catch this particular case no matter what.
Anyway, even if you could trap it, what were you going to do? If your
program needs 3.5, then the most appropriate thing is to create an
installer which checks whether 3.5 is installed, and if not, installs
it, or prompts the user to install it. A simple VS Setup project
should do it.
re: Downlevel .NET question
wrote:
Is there anything I can put in my program to trap this condition and give a
more useful error message? Or is the failure occurring as the program
loads, before it tries to execute?
In my case, the program uses an extension method, and that seems to be what
trips it.
Since an extension method translates to an instance of
ExtensionAttribute, and since attributes are (so far as I know)
instantiated when assembly is loaded, it would seem that you can't
catch this particular case no matter what.
Anyway, even if you could trap it, what were you going to do? If your
program needs 3.5, then the most appropriate thing is to create an
installer which checks whether 3.5 is installed, and if not, installs
it, or prompts the user to install it. A simple VS Setup project
should do it.
posted by Ben Voigt [C++ MVP] at 08/02/2008 04:00PM
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.22f8398542a828b1e71@msnews.microsoft.com...
news:MPG.22f8398542a828b1e71@msnews.microsoft.com...
MC <for.address.look@www.ai.uga.edu.slash.mc> wrote:
Well, it will do that in some cases - like if you use a type declared
in .NET 2.0 SP1 or .NET 3.0 SP1, or reference a .NET 3.5 assembly.
If you don't use anything that's not in .NET 2.0 (or 3.0 for Vista) is
should work fine.
Is there anything I can put in my program to trap this condition and give
a
more useful error message?
Not easily, as far as I know.
Or is the failure occurring as the program loads, before it tries to
execute?
I don't know, to be honest. I suggest you try it and see - try to write
code that calls a method in .NET 3.5, and see if you can get it to
execute at all.
My *guess* is that when the class that refers to a .NET 3.5 class is
first initialized, that's when it'll first go bang - but it could be at
the method level, or the whole assembly level...
[/quote:e74f4cf2c9]
Then have the exe not use any .NET 3.5, but invoke the "real" main method in
a library assembly and catch any exceptions?
i.e. change the current application to a class library project, and invoke
its Main method from a brand new shim.
[quote:e74f4cf2c9]
In my case, the program uses an extension method, and that seems to be
what
trips it.
Yes, there weren't any extension methods (or even the attribute) in
.NET 3.0.
--
Jon Skeet - <skeet@pobox.com
Web site: http://www.pobox.com/~skeet
Blog: http://www.pobox.com/
C# in Depth: http://www.pobox.com/