Call to LotusSession.GetDatabase works in VB but not in C#

I have some old VB code to send mails using Lotus Notes that works, I have re-written it into C#, but it behaves differently:


    NotesSession = CreateObject("Notes.Notessession")
    NotesDb = NotesSession.GetDatabase("", "")


    _notesSession = new NotesSession();
    _notesDatabase = _notesSession.GetDatabase( "", "");

First of in C# I need to Initialize the NotesSession with a password, and secondly it will not accept empty string parameters at runtime. Exception is thrown: "A database name must be provided".

In both VB and C# I refer to the same COM : Lotus Domino Objects

I need to be able to call the GetDatabase without specifying the server and database file.

Thanks in advance.

Solution (Thanks guys):

     dynamic _notesSession = Activator.CreateInstance(Type.GetTypeFromProgID("Notes.NotesSession"));
     _notesDatabase = _notesSession.GetDatabase("", "");

This way you have no intellisense but all properties and methods can be found here


When you create a new instance of the NoteSession type in C# using the new keyword, it will use the COM-interop dll that was referenced by the project at build-time. That is not exactly the same thing as calling CreateObject, which requires no interop dll. The closer equivalent in C# would be:

Type t = Type.GetTypeFromProgID("Notes.Notessession");
_notesSession = Activator.CreateInstance(t);

Or, if you really need to do the exact same thing, you could always add a reference to the Microsoft.VisualBasic.dll library and then call the Microsoft.VisualBasic.Interaction.CreateObject method from C#.

As Richard pointed out in the comments below, the likely reason why you are seeing a difference in behavior is because you are creating two different types of objects. Presumably, when you call new NotesSession in C#, it is using the NotesSession class from the Lotus namespace, rather than the one in the Notes namespace.

Need Your Help

Video encoding pipeline - threads design

multithreading encoding streaming video-capture video-processing

I work on a system which does video capture & encoding of multiple channels. each stage takes time. The capture/encoding is done in HW, but still can take its time to finish.

Why can't I see the colour of an object from 3ds Max in OpenGL?

c++ opengl graphics 3d textures

I want to make a room in OpenGl with Visual Studio 2010 and add some objects like a chair, carpet etc. I designed the walls only by using textures. I have some problems when I try to import objects...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.