开发者

Is there a way to unload or reload the currently loaded runtime?

Ever since we started upgrading some of our projects to .NET framework 4.0, I've been running into a lot 开发者_StackOverflow社区of issues regarding the following error:

This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

It's now happening with our installer application. The installer goes through a list of DLL's and installs the necessary ones on a target machine. Each assembly is loaded into context using

Assembly.LoadFile

The first assemblies in the queue are 3.5. Once the installer picks up a 4.0 DLL and tries to load it using Assembly.LoadFile, I get that error. It seems as though loading the first DLL sets the precedent as to which "runtime" is currently loaded.

Is there a way I can unload this currently loaded runtime before processing a 4.0 DLL in order to avoid this error?


This will depend on what CLR is the executable that is loading the assemblies running. If it runs on CLR 2.0 you won't be able to load a .NET 4.0 assembly. So make sure that if you try to load a .NET 4.0 assembly you are running the application on CLR 4.0. You mention the installer application. There's a possibility to set a launch condition requirement for .NET 4.0:

Is there a way to unload or reload the currently loaded runtime?


UPDATE:

You could also force your executable to be loaded by the CLR 4.0 by putting this in the app.config file:

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

Because the CLR 4.0 supports loading assemblies compiled against previous versions this will allow you to work around the problem without recompiling the executable against .NET 4.0.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜