混合模式程序集是针对运行时的“v2.0.50727”版本构建的,无法在 4.0 运行时中加载 - 研究的解决方案不起作用

Posted

技术标签:

【中文标题】混合模式程序集是针对运行时的“v2.0.50727”版本构建的,无法在 4.0 运行时中加载 - 研究的解决方案不起作用【英文标题】:Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime - Researched solutions not working 【发布时间】:2015-05-28 04:58:52 【问题描述】:

以下是我的完整错误:

Error in Microsoft.SqlServer.Dts.Runtime.TaskHost  
The Execute method on the task returned error code 0x80131621 (Mixed 
mode assembly is built against version 'v2.0.50727' of the 
runtime and cannot be loaded in the 4.0 runtime without 
additional configuration information.  The Execute method must succeed,
and indicate the result using an "out" parameter.

我找到了可能的解决方案 here 和 here 但是我仍然收到上述错误。

以下是我的表单代码:

private void button1_Click(object sender, EventArgs e)
    
        string pkgLocation;
        Package pkg;
        Microsoft.SqlServer.Dts.Runtime.Application app;
        DTSExecResult pkgResults;

        MyEventListener eventListener = new MyEventListener();

        pkgLocation =
          @"C:\FilePath.dtsx";

        app = new Microsoft.SqlServer.Dts.Runtime.Application();
        pkg = app.LoadPackage(pkgLocation, eventListener);
        pkgResults = pkg.Execute(null, null, eventListener, null, null);

        MessageBox.Show(pkgResults.ToString());

    

    class MyEventListener : DefaultEvents
    
        public override bool OnError(DtsObject source, int errorCode, string subComponent,
          string description, string helpFile, int helpContext, string idofInterfaceWithError)
        
            // Add application-specific diagnostics here.
            MessageBox.Show("Error in " + "/t" + source + "/t" + subComponent + "/t" + description);
            return false;
        
    

以下是我的 app.config 标记:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <supportedRuntime version="v2.0.50727" />
  </startup>
  </configuration>

为什么以前研究的解决方案对我不起作用?他们有很多赞成票,我推断它们对很多其他用户都有效。

【问题讨论】:

为什么是-1。旧的“否决票并运行”?为什么?我展示了我的代码,展示了研究,并建议研究的解决方案在我的标题中不适合我。请解释为什么投反对票。 第二个 supportedRuntime 部分被注释掉的任何原因?您引用的第一个答案已经表明可能会修复运行时不匹配。试过了吗? 它仍然无法在未注释的情况下使用...我只是在查看所有可能的解决方案,但没有一个有效。 @DarkBobG 我还需要将 app.config 添加到其他文件夹吗? 【参考方案1】:

通过@pabrams 找到答案here。 @pabrams 在答案 "Probably depends on what version of Visual Studio you're using, but for me (VS2010 Pro) it was Right-Click Project -&gt; hit Properties -&gt; Compile -&gt; Advanced Compile Options... -&gt; Generate serialization assemblies is a dropdown" 下附加评论

成功了!

【讨论】:

useLegacyV2RuntimeActivationPolicy="true" 也是关键

以上是关于混合模式程序集是针对运行时的“v2.0.50727”版本构建的,无法在 4.0 运行时中加载 - 研究的解决方案不起作用的主要内容,如果未能解决你的问题,请参考以下文章

混合模式程序集是针对“v2.0.50727”错误构建的

SQLite.dll混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。

c# .netframwork 4.0 调用 2.0时报错 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。

错误混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。

混合模式汇编异常[重复]

混合模式程序集是针对运行时的“2.0.50727”版本构建的,无法在 4.0 运行时中加载