다음을 통해 공유


COM 등록 메서드는 일치해야 합니다.

업데이트: 2007년 11월

TypeName

ComRegistrationMethodsShouldBeMatched

CheckId

CA1410

범주

Microsoft.Interoperability

변경 수준

주요 변경 아님

원인

형식에서 System.Runtime.InteropServices.ComRegisterFunctionAttribute 특성으로 표시된 메서드를 정의하지만 System.Runtime.InteropServices.ComUnregisterFunctionAttribute 특성으로 표시된 메서드를 선언하지 않거나 그 반대의 경우입니다.

규칙 설명

COM 클라이언트가 .NET Framework 형식을 만들려면 해당 형식이 먼저 등록되어 있어야 합니다. 가능한 경우 등록 프로세스 동안 ComRegisterFunctionAttribute 특성으로 표시된 메서드가 호출되어 사용자가 지정한 코드를 실행합니다. 등록 메서드의 작업을 되돌리려면 ComUnregisterFunctionAttribute 특성으로 표시된 해당 메서드를 등록 프로세스 동안 호출합니다.

위반 문제를 해결하는 방법

이 규칙 위반 문제를 해결하려면 해당하는 등록 또는 등록 취소 메서드를 추가합니다.

경고를 표시하지 않는 경우

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

예제

다음 예제에서는 규칙을 위반하는 형식을 보여 줍니다. 주석이 지정된 코드는 위반을 해결하는 방법을 나타냅니다.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary

   Public Class ClassToRegister
   End Class

   Public Class ComRegistration

      <ComRegisterFunctionAttribute> _ 
      Friend Shared Sub RegisterFunction(typeToRegister As Type)
      End Sub

'      <ComUnregisterFunctionAttribute> _ 
'      Friend Shared Sub UnregisterFunction(typeToRegister As Type)
'      End Sub

   End Class

End Namespace
using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(true)]
namespace InteroperabilityLibrary
{
   public class ClassToRegister
   {
   }

   public class ComRegistration
   {
      [ComRegisterFunction]
      internal static void RegisterFunction(Type typeToRegister) {}

//      [ComUnregisterFunction]
//      internal static void UnregisterFunction(Type typeToRegister) {}
   }
}

관련 규칙

COM 등록 메서드는 노출되면 안 됩니다.

참고 항목

개념

COM에 어셈블리 등록

참조

어셈블리 등록 도구(Regasm.exe)

System.Runtime.InteropServices.RegistrationServices