混合模式程序集是针对运行时版本 '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

以下是我的完整错误:

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 and 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>

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

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

下附加评论

成功了!