我怎样才能加载.NET程序集的旧版本?加载、旧版本、程序、NET

2023-09-03 16:28:17 作者:没有了海绵的宝宝

我有一个WPF / C#应用程序引用.NET 4.0组件。然而,在应用程序中是需要显示的C#智能感知依赖于.NET 3.5程序集文本编辑器。因此,我希望能够加载相应的.NET 3.5组件在运行时。然而,当我尝试使用:

I have a WPF/C# application that references .NET 4.0 assemblies. However, within the application is a text editor that needs to display C# intellisense tied to .NET 3.5 assemblies. Thus, I want to be able to load the appropriate .NET 3.5 assemblies at runtime. However, when I try to use:

Assembly.Load()
Assembly.LoadFile()
Assembly.LoadFrom()

我总是得到最新的版本从GAC。阅读他们的MSDN网页,好像那是很不幸设计。

I always get the latest version from the GAC. Reading their MSDN pages, it seems like that's unfortunately by design.

我想按照这个建议的解决方案stack溢出后。然而,链接网页的解决方案不工作,远程处理过程似乎有点小题大做。有谁知道一个更好的和/或更简单的方法,以在运行时加载较旧的.NET程序集?

I tried following the proposed solutions in this stack overflow post. However, the linked webpages' solutions don't work and a remoting process seems like overkill. Does anyone know a better and/or easier way to load older .NET assemblies at runtime?

推荐答案

您可以在您的app.config或web.config中,取适当的使用AssemblyBinding属性。

You can use the AssemblyBinding property in your app.config or web.config, whichever is appropriate.

例如,我的接口与Matlab的,所以我需要这个...

For instance, I'm interfacing with Matlab, so I need this...

<loadFromRemoteSources enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="MWArray" publicKeyToken="E1D84A0DA19DB86F" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0" />
        </dependentAssembly>
    </assemblyBinding>

由于Matlab引擎我和编译工作,使用运行时的不同副本的机器上(怎么有些疯狂)。

Because the Matlab engine I work with is compiled (some crazy how) on a machine using a different copy of the runtime.

您应该能够修改此code,以满足您的需求。

You should be able to modify this code to suit your needs.