can't find anything on early binding that is not VBA, kind of lost on this one. Code as follows.

Private Sub FabViewFeedBackToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FabViewFeedBackToolStripMenuItem.Click
  'send email to me via outlook
  Dim Outl As Object
  Outl = CreateObject("Outlook.Application")

  If Outl IsNot Nothing Then
    Dim omsg As Object
    omsg = Outl.CreateItem(0)
    omsg.To = "[email protected]"
    omsg.subject = "FabView FeedBack"
    omsg.Display(True) 'will display message to use
  End If
End Sub

downloaded NuGet Microsoft Office outlook interop package

2

There are 2 best solutions below

1
SSS On

Instead of binding to Outlook (which can be unreliable), you could instead shell to default mail client as follows:

VB.NET:

Dim recipientEmail = "[email protected]"
Dim emailSubject = "Application FeedBack"
Dim sInfo As ProcessStartInfo = New ProcessStartInfo($"mailto:{recipientEmail}?subject={emailSubject}") With {.UseShellExecute = True}
System.Diagnostics.Process.Start(sInfo)

C#:

var recipientEmail = "[email protected]";
var emailSubject = "Application FeedBack";
ProcessStartInfo sInfo = new ProcessStartInfo($"mailto:{recipientEmail}?subject={emailSubject}") { UseShellExecute = true };
System.Diagnostics.Process.Start(sInfo);
0
Albert D. Kallal On

Your example posted vb.net code IS LATE binding.

I mean, you CAN use the office interop libaries (PIO's), but then again, since you currently ARE using late binding, then I would continue to do so.

So, then, we only really need to get/grab/know/find/learn what the equivalent code of CreateObject in c# is, and we can write that same functional code in c#.

In fact, in MOST cases, even going back to VB6, or VBA code?

It is MUCH better to get the EXISTING copy of Outlook if it is running, and use GetObject. That not only runs MUCH faster, but then you using the current loaded outlook copy, and that can effect what profile the user is curretnly using (they might have 5 email accounts - which one you going to use?).

Anyway, since your existing code "badly" is using CreateObject, then we will continue to adopt that "bad" choice and do the same.

So, same code in c# would thus be:

        // send email to me via outlook
        dynamic Outl = Interaction.CreateObject("Outlook.Application");

        if (Outl != null)
        {
            dynamic omsg = Outl.CreateItem(0);
            omsg.To = "[email protected]";
            omsg.subject = "FabView FeedBack";
            omsg.Display(true); // will display message to use
        }
    }

So, I "am open" to posting a early binding example, but since your above example and code is late binding, then I not sure it worth the effort and time to post some early binding code.

And to be REALLY fair? What .net does behind is use the office inter-op assemblies ONLY to show you methods with intel-sense, and in fact for the last 20 years, .net net office PIO's actually ALWAYS used late binding!!!!

but, as above shows, your vb.net code was late binding, and you can do the same in c# with above.