简体   繁体   中英

How to use an Interface of external dll in c#

I need to use some methods that in an external dll, I have already done something like that, but this time that external dll is an Interface.

I do like this:

Assembly Assembly = Assembly.LoadFrom("fullpathofdll"); 
Type Type = Assembly.GetType("mytype"); 
dynamic Instance = Activator.CreateInstance(Type);

But I got this error: Cannot create an instance of an interface

I understand that's not possible instaciate an interface, but I don't know how to do this to work.

Someone can help?

An interface is supposed to be a "contract" for you to implement, not instantiate. Your own implementation of the interface can then be instantiated via reflection the way you're doing above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM