我有一个32位的.NET类库,其中包含一个简单的公共类和一个简单的公共方法。我有一个64位的.NET控制台应用程序,在使用反射时,我希望加载32位程序集并调用其方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Host.TestLib;
namespace test
{
class Program
{
static void Main(string[] args)
{
var lib = Assembly.LoadFrom("Simple32bitAssembly.dll");
}
}
}
当我运行这个程序时,会抛出以下异常:
System.BadImageFormatException was unhandled
Message=Could not load file or assembly
'file:///E:\AjitTemp\c\32bit64Bit\ReflectionTest\test\bin\Debug\Simple32bitAssembly.dll'
or one of its dependencies. An attempt was made to load a program with an incorrect format.
搜索结果显示,我需要为这个32位dll创建一个64位的包装器,并在我的64位控制台应用程序中使用反射加载此包装器?这是正确的方法吗?任何示例代码都将非常有帮助。