What establishes the framework an assembly runs under?


Steve Franks

Does anyone know what establishes the framework an assembly will run under?
For example, when I look at my custom assembly (C# library) in the GAC, the
Runtime column shows it will run under the .NET framework version 1.1.4322.
How is the GAC determining/setting this? I did not explictly do anything in
my code or build options to specify this. On my machine I have frameworks
1.0, 1.1 as well as 2.0 beta.

My assembly was created using Visual Studio 2003 - does this have something
to do with it?

Now, what would happen if I tried to run that same assembly under framework
1.0? Would it run or error out?

Likewise I'm thinking that if I recompile my assembly under Visual Studio
2005 beta 2 that the runtime would change to v2.0. However, again, would
this mean that the assembly would not run on a machine that did not have
the 2.0 framework installed? I am not using any particular features that
are specific to 2.0 (or even 1.1 for that matter)?

Along these same lines, how does one use the latest version of VS.NET (say
2005 beta 2) and yet still make sure that their assembly will run on
framework 1.0?

Thank you!





The GAC determines framework by which compiler was used. If you use the 1.0
compiler, it is 1.0 and is 1.1 if not.

To use an assembly across frameworks, you need a service wrapper. You
cannot, at least without a major fudging, use a 1.1 assembly in a 1.0
project. There are some exceptions to this rule, of course, as 1.0 ASP.NET
assemblies can be dropped in a 1.1 project (if there are no breaking IL
changes - stay away from XML), but they will be treated as 1.1 if you do
this, not 1.0. The GAC is different, however, as it more firmly bonds the CLR
version to the assembly.

To the final quesiton. If you are using 2.0, you will have to stay away from
using any new code that cannot compile to 1.0 ... or, you will have to wrap
your code inside of a service (Remoting or ASMX) and call the service from
your 1.0 code.

Gregory A. Beamer

Think Outside the Box!



Steve Franks

Thanks. I have some clarifications please.

For this discussion please assume the scenario where I use Visual Studio
2005 beta 2 to compile my assembly. This assembly does NOT use any code,
classes, interfaces, etc that are specific to framework 2.0. In other
words, this same exact code would compile just fine under say the original
VS.NET 1.0. The only difference is that I am compiling it with VS 2005. As
I understand it, at this point the GAC will list it as version 2.x.x.x.

1) Are you saying that if I gave this assembly to someone to use on a
machine that did not have the 2.0 framework installed, that it would not run
without a special wrapper or doing something tricky? What would happen
exactly - an error message?

2) Is there an option within Visual Studio where you tell it what version of
the framework you are targetting? In other words, I'd like to tell VS that
I want my compiled assembly to work with the original 1.0 framework, and
then have it produce an assembly that will run in that ok, and warn me if at
any time I use a class or other function that is not available under my
target framework.



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question