How to enforce managed code be executed under .net 2.0 in .net 4 process (SxS)

StackOverflow https://stackoverflow.com/questions/9070819

  •  20-04-2021
  •  | 
  •  

Вопрос

In some articles people mention "explicit run sxs". Is it actually possible? I've read several articles concerning the topic:
http://msdn.microsoft.com/en-us/magazine/ee819091.aspx
http://blogs.msdn.com/b/dotnet/archive/2009/06/03/in-process-side-by-side-part1.aspx
http://msdn.microsoft.com/en-us/library/ee518876.aspx

but it's still not clear if it's possible to enforce a piece of managed code be executed under older .net version from .net 4 process.

So far it looks like the only COM components can require older .net so .net 4 clr will automatically start SxS execution. Could someone shed light on this question?

Это было полезно?

Решение

Using the compiler generated CLR host, no I don't think you can do this.

I believe you would have to host the CLR yourself and explicitly specify which CLR you wanted to load when calling CorBindToRuntimeEx. So you want load one CLR by specifying v2, and another specifying v4.

Previously, you couldn't do this at all, it would crash spectacularly.

You can't really say, "Oh, I just want this method to run in the CLR v2". Your "piece of managed code" will be in a different AppDomain, so you will have to do some sort of communication between the two AppDomains, such as remoting.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top