nitinumap,
There are two issues here:
1)
>Dim obj As New IMyInterface
You cannot create an instance of an interface, instead you can declare a variable of the interface's type and set it to an instance of a class that implements the interface.
Dim obj As IMyInterface = New
ClassThatImplementsTheInterface
2)
Vsta add-ins should use a factory method to get a host object instead of creating an instance. This is so that all objects are created on the host side and marshaled across through the proxy layer instead of relying on the add-in to provide management for the object.
Below is some code that shows how to do this on the host and add-in side. For more information on this, you may want to check out our
EventSample which demonstrates how to implement this.
I hope this helps, please let me know if you have any questions.
Thanks,
-Melody
'Host (Application class)
Public Function getIMyInterface() As IMyInterface
Dim obj As IMyInterface = New ClassThatImplementsTheInterface
Return obj
End Function
Public Class ClassThatImplementsTheInterface
Implements IMyInterface
End Class
Public Interface IMyInterface
End Interface
'Add-in
Private Sub AppAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
'create a new object using the factory method
Dim iObj As IMyInterface = Application.getIMyInterface("hello")
End Sub