0

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

  • Do you have the "libraryname.dll" file on your machine? – James Oravec Feb 22 '13 at 15:24
  • Yes I copied it from the VS2010 development machine to the VS2003 development machine, then I tried to added as a file reference. – dggonzalez Feb 22 '13 at 15:30
  • This cannot work, you can only use .NET 1.x assemblies in VS2003. Creating .NET 1.x assemblies in VS2010 is not possible. High time you retire VS2003, ten years are a lot of dog lives in software engineering, especially for web apps. – Hans Passant Feb 22 '13 at 16:16

2 Answers2

0

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

Community
  • 1
  • 1
PmanAce
  • 4,000
  • 2
  • 24
  • 29
0

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.

Stefano Altieri
  • 4,550
  • 1
  • 24
  • 41
  • Thanks, it is working now, at least the service with the .NET 1.1 email solution I had before, anyway I'll have to upgrade my web app to the latest .NET framework but it will be later this year. – dggonzalez Feb 22 '13 at 17:45