1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual Studio 2013 で COM の相互運用アセンブリで System.BadImageFormatException が出て困った

Posted at

Visual Studio 2013 で COM の Windows Script Host Object Model を参照設定に追加していたところ、.NET Framework 3.5 でビルドして実行したら下記のエラーになりました。

型 'System.BadImageFormatException' のハンドルされていない例外が IEInstaller.exe で発生しました

追加情報:ファイルまたはアセンブリ 'Interop.IWshRuntimeLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'、またはその依存関係の 1 つが読み込めませんでした。このアセンブリは現在読み込まれているランタイムより新しいランタイムでビルドされているため、読み込むことができません。

.NET Framework 4.5.1 でビルドすると問題ありません。

ildasmInterop.IWshRuntimeLibrary.dll を見てみたところ、メタデータのバージョンが v4.0.30319 とかなっており、3.5 用のアセンブラになっていないっぽいです。

Visual Studio 2013 の tlbimp だと 3.5 用には相互運用アセンブリを作ることができないということなんでしょうかね。


C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bintlbimp があったので、こいつを使って次のようにアセンブリを作成して、

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" C:\Windows\system32\wshom.ocx

作成された IWshRuntimeLibrary.dll をファイルとして参照設定に追加すれば解決しました。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?