0

I'm trying to convert an old VB6 file into a VB.net (which I have never used before) one... I'm getting an error on this line:

Dim JMail As Object
JMail = Server.CreateOBject("JMail.Message")

saying 'Server is not declared'

I have:

Imports System.Web

at the top - which I thought gave me access To Server.CreateObject???

2
  • 1
    Oh man, Server.CreateObject brings back (mostly bad) memories of ASP Classic and VB6 development at my first job. I do no envy your situation of needing to port this over. Best of luck Commented Mar 12, 2013 at 17:36
  • You know that JMail has a .net version which would allow you to use more idiomatic .net code dimac.net/default2.asp?M=Products/MenuDOTNET.asp&P=Products/… Commented Mar 12, 2013 at 18:14

1 Answer 1

1

There's not really a direct equivalent to Server.CreateObject in .NET since everything is strongly typed, though you might be able to use System.Type.GetTypeFromProgID and invoke various methods using InvokeMember (Ick). Something like:

Type proxyType = System.Type.GetTypeFromProgID("JMail.Message");
object proxy = Activator.CreateInstance(proxyType);
object result = proxyType.InvokeMember("MemberName",
   // System.Reflection.BindingFlags
   null,
   proxy,
   // An object array with your parameters for this call
);

The best solution is probably to create a COM wrapper around your library, and reference it in your solution.

If you could provide some more details about what exactly your code does, perhaps someone could suggest a native way to accomplish that in .NET. For example, if you're just trying to send email or something, there's a million ways to do that in .NET.

Update: Just get JMail.NET, no need to deal with old ActiveX libraries anymore.

Sign up to request clarification or add additional context in comments.

5 Comments

What about Activator.CreateInstance? msdn.microsoft.com/en-us/library/… (full declaimer, I don't have an environment where I can test if this will help, just googling)
@JasonSperske - Sure, but you'll still be calling InvokeMember and what not, since the compiler can't resolve the type information. The proxy implementation would be doing all this internally, and the typelib importer will generate all that code for you.
Rightness has been restored, I'm glad I haven't added to the problem of too much legacy code in production :)
I'm trying to read a pop mail server...? any suggestions on how to not use JMAIL as this is not working.
@tree - The best solution is gonna be upgrading to the .NET version of JMail :) Trust me, trying to muck with ActiveX/COM libraries in .NET code is not fun. Unless you're an expert, or one owes you a favor, I would stay away from that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.