다음을 통해 공유


CA1412: ComSource 인터페이스를 IDispatch로 표시하십시오.

TypeName

MarkComSourceInterfacesAsIDispatch

CheckId

CA1412

범주

Microsoft.Interoperability

변경 수준

주요 변경

원인

형식이 ComSourceInterfacesAttribute 특성으로 표시되어 있으며 하나 이상의 지정된 인터페이스가 InterfaceTypeAttribute 특성이 InterfaceIsDispatch 값으로 설정된 것으로 표시되어 있지 않습니다.

규칙 설명

ComSourceInterfacesAttribute는 클래스가 COM(Component Object Model) 클라이언트에 노출시키는 이벤트 인터페이스를 식별하는 데 사용됩니다.이들 인터페이스가 InterfaceIsIDispatch로 노출되어야 Visual Basic 6 COM 클라이언트가 이벤트 알림을 받을 수 있습니다.기본적으로 인터페이스가 InterfaceTypeAttribute 특성으로 표시되어 있지 않으면 이중 인터페이스로 노출됩니다.

위반 문제를 해결하는 방법

이 규칙 위반 문제를 해결하려면 InterfaceTypeAttribute 특성을 추가하거나 수정하여 해당 특성의 값이 ComSourceInterfacesAttribute 특성으로 지정된 모든 인터페이스에 대해 InterfaceIsIDispatch로 설정되도록 합니다.

경고를 표시하지 않는 경우

이 규칙에서는 경고를 표시해야 합니다.

예제

다음 예제에서는 인터페이스 중 하나가 규칙을 위반하는 클래스를 보여 줍니다.

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
using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(true)]
namespace InteroperabilityLibrary
{
   // This violates the rule for type EventSource.
   [InterfaceType(ComInterfaceType.InterfaceIsDual)]
   public interface IEventsInterface
   {
      void EventOne();
      void EventTwo();
   }

   // This satisfies the rule.
   [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
   public interface IMoreEventsInterface
   {
      void EventThree();
      void EventFour();
   }

   [ComSourceInterfaces(
      "InteroperabilityLibrary.IEventsInterface\0" + 
      "InteroperabilityLibrary.IMoreEventsInterface")]
   public class EventSource
   {
      // Event and method declarations.
   }
}

관련 규칙

CA1408: AutoDual ClassInterfaceType을 사용하지 마십시오.

참고 항목

작업

방법: COM 싱크에서 처리하는 이벤트 발생

기타 리소스

비관리 코드와의 상호 운용