cs-script.npp icon indicating copy to clipboard operation
cs-script.npp copied to clipboard

How do I connect the dll?

Open it19862 opened this issue 4 years ago • 3 comments

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. 01

I placed the library as shown in the picture. MSACCESS_2021-07-06_22-47-38 02

Code How_to_connect_dll_01.cs

//css_reference ../Folder_dll/Interop.Microsoft.Office.Interop.OneNote.dll

using System;
using Microsoft.Office.Interop.OneNote;

namespace Folder_NS_02
{
	class  Test
	{
		static void GetNamesAllBooksInClipboard2()
		{
			var onenoteApp = new Application2();		
		}		
	}
} 

it19862 avatar Jul 06 '21 19:07 it19862

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 = "[email protected]";
email.Subject = "test subject";
email.Body = "test body";

email.Send();

Then you do not need to reference any assemblies at all. works.

oleg-shilo avatar Jul 08 '21 12:07 oleg-shilo

@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

it19862 avatar Jul 08 '21 12:07 it19862

great

oleg-shilo avatar Jul 08 '21 12:07 oleg-shilo