开发者

.NET framework requiredRuntime flag

开发者 https://www.devze.com 2023-01-26 19:49 出处:网络
I can use this flag to load a particular version of .NET framework by putting this flag in application configuration file of a binary. But the configuration file of binary is not in my control, as I a

I can use this flag to load a particular version of .NET framework by putting this flag in application configuration file of a binary. But the configuration file of binary is not in my control, as I am responsible for DLL. Is there any way I could specify the same flag in DLL, so that DLL could load other DLLs built with framework 4.0?

For example, Binary A.exe built with target framework 3.5, loads DLL B.dll with target framewo开发者_StackOverflow中文版rk 3.5. Now B.dll loads DLL C.dll which is built with target framework 4.0.

I could do it by putting the following configuration in app.config of A.exe.

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    <requiredRuntime version="v4.0"/>
  </startup>

I am not in control of A.exe and app.config, but I have control over B.DLL and C.DLL. Do you think it is possible?

-Thanks,

-Brajesh


This is not possible due to the loading process. By the time the request to load your DLL is made, the .NET Framework has already been loaded into the process. Before .NET 4, you could only have one version of the CLR in process at a time. (N.B. .NET 2.0, 3.0, and 3.5 all ran on the CLR 2.0.) Even with .NET 4, which allows CLR 2.0 and CLR 4.0 to co-exist in the same process, they have to run in separate AppDomains. You can't seamlessly communicate between different AppDomains.

One possible idea... Have a small CLR 2.0 shim that creates a separate CLR 4.0 AppDomain, loads your .NET 4.0 assemblies into it, and then communicates with it. This isn't going to be straightforward, easy, or performant. Another option would be to host your assemblies in a separate process and use named pipes, TCP, or some other communication channel to communicate between your .NET 4.0 code and a .NET 3.5 shim hosted in the existing EXE.

If the host application is .NET 3.5, I would say stick to .NET 3.5 for your assemblies. It's going to be a lot less headaches.

0

精彩评论

暂无评论...
验证码 换一张
取 消