|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Mark ComSource interfaces as IDispatch
A type is marked with the System.Runtime.InteropServices.ComSourceInterfacesAttribute attribute and at least one the specified interfaces is not marked with the System.Runtime.InteropServices.InterfaceTypeAttribute attribute set to ComInterfaceType.InterfaceIsIDispatch.
ComSourceInterfacesAttribute is used to identify the event interfaces that a class exposes to COM clients. These interfaces must be exposed as InterfaceIsIDispatch to allow Visual Basic 6 COM clients to receive event notifications. By default, if an interface is not marked with the InterfaceTypeAttribute attribute, it is exposed as a dual interface.
The following example shows a class where one of the interfaces violates the rule.
Imports Microsoft.VisualBasic Imports System Imports System.Runtime.InteropServices <Assembly: ComVisibleAttribute(True)> Namespace InteroperabilityLibrary ' This violates the rule for type EventSource. <InterfaceType(ComInterfaceType.InterfaceIsDual)> _ Public Interface IEventsInterface Sub EventOne Sub EventTwo End Interface ' This satisfies the rule. <InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _ Public Interface IMoreEventsInterface Sub EventThree Sub EventFour End Interface <ComSourceInterfaces( _ "InteroperabilityLibrary.IEventsInterface" & _ ControlChars.NullChar & _ "InteroperabilityLibrary.IMoreEventsInterface")> _ Public Class EventSource ' Event and method declarations. End Class End Namespace