質問

約2年前にデータベースアクセス用の.NET 2.0にクラスライブラリを書き、.NET 2.0、3.0、および3.5でずっと使用しています。

私が取り組んでいる現在のプロジェクト(.NET 4.0アプリケーション)では、古い忠実なクラスライブラリを使用してみましたが、次の例外が得られました。


System.InvalidOperationException was unhandled
  Message=An error occurred creating the form. See Exception.InnerException for details.
    The error is: 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.
    Source=SchoolManager
  StackTrace:
       at SchoolManager.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
       at SchoolManager.My.MyProject.MyForms.get_frmGeneric()
       at SchoolManager.My.MyApplication.OnCreateMainForm() in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\My Project\Application.Designer.vb:line 35
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at SchoolManager.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.FileLoadException
       Message=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.
       Source=Dinofage.Data.XpressData
       StackTrace:
            at Dinofage.Data.XpressData.ExecuteSelectInternal(String selectCommand)
            at Dinofage.Data.XpressData.ExecuteSelect(String selectCommand)
            at SchoolManager.Academics.GetNewAdmissionCode(String academicYear) in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\Modules\Academics.vb:line 89
            at SchoolManager.StudentDetail..ctor() in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\UserControls\StudentDetail.vb:line 20
            at SchoolManager.frmGeneric.InitializeComponent() in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\frmGeneric.Designer.vb:line 25
            at SchoolManager.frmGeneric..ctor()
       InnerException: 

何が間違っている可能性があり、どうすれば修正できますか?

役に立ちましたか?

解決

おそらく、Visual Studio 2010の.NET 4.0のクラスライブラリを再コンパイルすることです(つまり、プロジェクトを開き、変換し、ターゲットフレームワークを変更します。)

できない場合、またはそうしない場合は、.NET 4.0アプリケーションのapp.configファイルに次のものを追加してみてください。

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>

すなわち。

<?xml version ="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
    </startup>
</configuration>

他のヒント

アセンブリは混合モードであるため、アセンブリ内の管理されていないマシンコードからマネージドコードを呼び出す可能性があります。 .NET 4.0での新しいインプロセスのCLRバージョンのサポートにより、ランタイムは、それが発生したときにどのCLRバージョンを提供する必要があるかを知りません。このように見えるはずのapp.exe.configファイルでそれを伝える必要があります。

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

別の方法:VB 2010 Expressでは、プロジェクトを開いてタブコンパイルに移動してから、 Advanced Compile Options.... 。選択する .NET Framework 2.0 名前付きのドロップダウンリストから Target framework (all configurations).

uselegacyv2runtimeactivationpolicy = "true"を指定しても通り抜けていない場合は、OSと.NETバージョンと互換性のあるセットアップをインストールする必要がある場合があります。あなたはで同じことを見つけることができます http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki.

このセットアップをインストールする前に、インストールされたプログラムからSQLiteをアンインストールします。これにより、コードのエラーが表示されます。

互換性のあるセットアップをインストールした後でも機能していない場合は、以前のDLLファイルへの参照を削除し、この互換性のあるDLLファイルに新しい参照を追加する必要があります。

互換性のあるDLLファイルへの参照を追加すると、プロジェクトを構築するだけで、すべてのコードエラーが発生するはずです。

Visual Studio 2010の中に古い忠実なプロジェクト(クラスライブラリ)を開いて、それがあなたのために変換を行うことを許可することを試みることができます。

他の誰かがまだこの問題に遭遇した場合、ここに私の診断があります:あなたは間違ったSQLiteパッケージを使用しています。 sqliteには多くのバージョンがあります http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

たとえば、x86プラトルムで.NET 4.5をターゲットにしている場合は、このファイルを使用する必要があります。

32ビットウィンドウ用の静的にリンクされたバイナリを事前縮小した(.NETフレームワーク4.5)

sqlite-netfx45-static-bundle-win32-2012-1.0.106.0.zip

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top