これはVisual Studio 2017 V15.5.2であり、提案された修正は適用されません。Visual Studio Testとフォームアプリケーション
"Dim comp"行の例外を除いて実行できない単純なテストがあります。
System.BadImageFormatException:「ファイルまたはアセンブリをロードできませんでした 'System.IO.FileSystem、バージョン= 4.0.1.0、文化=中立、なPublicKeyToken = b03f5f7f11d50a3a' またはその依存関係の1つ。参照アセンブリは、実行のために読み込まれるべきではありません。それらは、Reflection-onlyローダーコンテキストでのみロードできます。 (HRESULTからの例外:0x80131058) '
以下のテストコードは、Windowsフォームアプリケーションにコピーするとほぼ同じコードが完全に動作します。いくつかのスニからの助けと一つの追加のステップに
Public Class Form1
Dim tree As SyntaxTree = VisualBasicSyntaxTree.ParseText("Imports System
Imports System.Collections.Generic
Imports System.Text
Class TestClass
Private Sub TestMethod()
Dim x = ""Hello, World!""
End Sub
End Class")
Dim comp As Compilation = VisualBasicCompilation.Create("HelloWorld").
AddReferences(MetadataReference.CreateFromFile(GetType(Object).Assembly.Location),
MetadataReference.CreateFromFile(GetType(Form1).Assembly.Location)).
AddSyntaxTrees(tree)
Dim model As SemanticModel = comp.GetSemanticModel(tree)
End Class
[BadImageFormatExceptionのトラブルシューティング]の可能な複製(https://stackoverflow.com/questions/8996653/troubleshooting-badimageformatexception) – Sunil
フレームワークを.Net 4.6.2に変更してプログラムを動作させましたが、4.7.1に戻しましたそれは失敗する。 –