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

有些话、适合烂在心里 提交于 2021-02-07 09:24:25

问题


The following is my full error:

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.

I have found possible solutions here and here however I am still getting the above error.

The following is my form code:

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;
        }
    }

The following is my app.config markup:

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

Why are the previous researched solutions not working for me? They have lots of upvotes which I deduce have worked for a lot of other users.


回答1:


Found answer here via @pabrams. @pabrams additional comment under answer "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"

did the trick!



来源:https://stackoverflow.com/questions/29240142/mixed-mode-assembly-is-built-against-version-v2-0-50727-of-the-runtime-and-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!