我有一个使用VS2003 Ver 7.1.6030开发的.NET 1.1 Web应用程序,使用VB.NET作为代码;我最近在VS2010 .NET 4.0中创建了一个类库,添加了能够使用System.Mail SmptClient发送电子邮件但是当我尝试添加对我的.NET 1.1项目的引用时,它给了我以下错误:
“无法添加对libraryname.dll的引用。这不是有效的程序集或COM组件。只能扩展名为“dll”和COM组件的程序集。请确保该文件是可访问的,并且它是有效的程序集或COM组件。“
我做错了什么?这可能吗?
非常感谢你的帮助!
大卫
答案 0 :(得分:0)
尝试类似下面的内容(暂时发现并将其保留在我的笔记中):
// Load the assembly
Assembly a = Assembly.LoadFile(@"C:\PathHere\DLL.dll");
// Load the type and create an instance
Type t = a.GetType("ClassLibrary.ClassName");
object instance = a.CreateInstance("ClassLibrary.ClassName");
// Call the method
MethodInfo m = t.GetMethod("MethodName");
m.Invoke(instance, new object[] {}); // Get the result here
以下是参数的更详细示例:Reflection: How to Invoke Method with parameters
答案 1 :(得分:0)
您不能直接在.net 1.1项目中使用.net 4 dll(您可以改为使用1.1 in 4)。 唯一的解决方案(除非您可以升级框架版本)是包装您的功能(即在WCF自托管服务中)并通过Web服务或其他IPC技术使用它。