我有一个用.NET 4.5.2编写的工具,它使用反射生成代理输出文件。您将工具指向DLL并生成输出。
使用Assembly.Load加载Assembly或EXE,但是当它指向使用4.5.2框架(\ bin \ Debug \ net452文件夹中的输出)编译的ASP.NET Core 1.0 RTM应用程序时,它得到以下异常:
Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Code\Test452Web\bin\Debug\net452\Test452Web.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at TypeScriptTypingsGenerator.Program.Main(String[] args) in C:\Code\TypeScriptTypingsGenerator\TypeScriptTypingsGenerator\Program.cs:line 31
由于ASP.NET CORE应用程序也在4.5.2中编译,我认为它应该能够加载到AppDomain中。这样做的正确方法是什么?