Closed it19862 closed 7 months ago
The error indicates that you are referencing two dll's: 'Interop.Microsoft.Office.Interop.OneNote, Version=1.1.0.0' and 'Microsoft.Office.Interop.OneNote, Version=15.0.0.0'.
It might be because VS created for a collable wrapper and cs-script picks them both wrapper and the assembly when it tries to resolve nemespace Microsoft.Office.Interop.OneNote
into assembly.
The easiest way to check it is to try this:
//css_reference ../Folder_dll/Interop.Microsoft.Office.Interop.OneNote.dll
using System;
namespace Folder_NS_02
{
class Test
{
static void GetNamesAllBooksInClipboard2()
{
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application2();
}
}
}
This may solve your problem but I would recommend you to go with dynamic instantiation instead even if the trick shared:
dynamic outlook = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application"));
dynamic email = oApp.CreateItem(0);
email.To = "me@gmail.com";
email.Subject = "test subject";
email.Body = "test body";
email.Send();
Then you do not need to reference any assemblies at all. works.
@oleg-shilo I just did it this way.
using System;
using Microsoft.Office.Interop.OneNote;
namespace Folder_NS_02
{
class Test
{
static public void Main(string[] args)
{
var onenoteApp = new Application2();
string currentNotebookId = onenoteApp.Windows.CurrentWindow.CurrentNotebookId;
Console.WriteLine(currentNotebookId);
}
}
}
It works
great
I'm getting an error: Error CS0433: Type 'Application2' exists in both 'Interop.Microsoft.Office.Interop.OneNote, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' and 'Microsoft.Office.Interop.OneNote, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
I took the library from Visual Studio.
I placed the library as shown in the picture.
Code How_to_connect_dll_01.cs