Question

I have a .NET 1.1 web app developed using VS2003 Ver 7.1.6030, using VB.NET as code behind; I recently created a Class Library in VS2010 .NET 4.0 to add be able to send emails using System.Mail SmptClient but when I try to add the reference to my .NET 1.1 project it gives me the following error:

“A reference to libraryname.dll could not be added. This is not a valid assembly or COM component. Only assemblies with extension ‘dll’ and COM components can be reference. Please make sure that the file is accessible, and that it is a valid assembly or COM component.”

What am I doing wrong? Is this possible?

Thanks a lot for your help!

David

Was it helpful?

Solution

You can't use a .net 4 dll in a .net 1.1 project straightforward (you can instead use 1.1 in 4). The only solution (unless you can upgrade framework version) is wrap your functionality (i.e. in a WCF self hosted service) and use it via web service or other IPC techniques.

OTHER TIPS

Try something like the following (found this a while ago and keep it in my notes):

// 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

Here is a more detailed example with parameters: Reflection: How to Invoke Method with parameters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top