다음을 통해 공유


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

업데이트: 2007년 11월

TypeName

ComRegistrationMethodsShouldNotBeVisible

CheckId

CA1411

범주

Microsoft.Interoperability

변경 수준

주요 변경

원인

System.Runtime.InteropServices.ComRegisterFunctionAttribute 또는 System.Runtime.InteropServices.ComUnregisterFunctionAttribute 특성으로 표시된 메서드를 외부에서 볼 수 있습니다.

규칙 설명

어셈블리가 COM에 등록될 때 레지스트리에 어셈블리의 각 COM 노출 형식에 대한 항목이 추가됩니다. 등록 및 등록 취소 프로세스 동안 각각 ComRegisterFunctionAttributeComUnregisterFunctionAttribute 특성으로 표시된 메서드가 호출되어 이들 형식의 등록/등록 취소와 관련된 사용자 코드를 실행합니다. 이 코드는 이 프로세스 외부에서 호출되어서는 안 됩니다.

위반 문제를 해결하는 방법

이 규칙 위반 문제를 해결하려면 메서드의 액세스 가능성을 private 또는 internal(Visual Basic의 경우 Friend)로 변경하십시오.

경고를 표시하지 않는 경우

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

예제

다음 예제에서는 이 규칙을 위반하는 두 메서드를 보여 줍니다.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary

   Public Class ClassToRegister
   End Class

   Public Class ComRegistration

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

      <ComUnregisterFunctionAttribute> _ 
      Public 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]
      public static void RegisterFunction(Type typeToRegister) {}

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

관련 규칙

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

참고 항목

개념

COM에 어셈블리 등록

참조

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

System.Runtime.InteropServices.RegistrationServices