Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue about embedded interop types #12

Closed
KinsonWong opened this issue Jan 5, 2023 · 1 comment
Closed

Issue about embedded interop types #12

KinsonWong opened this issue Jan 5, 2023 · 1 comment

Comments

@KinsonWong
Copy link

KinsonWong commented Jan 5, 2023

Coding with Net Framework 4.8

I want to Refer "Microsoft.Office.Interop.Excel" which is embedded interop types while compile a class.

If I use dynamic type,it can compile succefully and run.

public class Module{
		public void Main(){
			dynamic xlApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
			dynamic wb = xlApp.Workbooks.Add();
			MessageBox.Show(wb.Name);
		}
	}

When I change the Type, compile Error occur.

public class Module{
		public void Main(){
			var xlApp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
			var wb = xlApp.Workbooks.Add();
			MessageBox.Show(wb.Name);
		}
	}
@RickStrahl
Copy link
Owner

You need to add a reference to the Interop assembly most likely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants