Sdílet prostřednictvím


CA1410: By odpovídal registrace metod modelu COM

Název_typu

ComRegistrationMethodsShouldBeMatched

CheckId

CA1410

Kategorie

Microsoft.interoperability

Změnit rozdělení

Bez rozdělení

Příčina

Typ deklaruje metodu, která je označena System.Runtime.InteropServices.ComRegisterFunctionAttribute atribut ale nedeklaruje metodu, která je označena System.Runtime.InteropServices.ComUnregisterFunctionAttribute atribut, nebo naopak.

Popis pravidla

Objekt modelu COM (Component) klientům vytvořit .NET Framework typu, typ musí být nejprve registrována.Pokud je k dispozici, metoda, která je označena ComRegisterFunctionAttribute atributu se nazývá během procesu registrace spustit kód zadaný uživatelem.Odpovídající metodě, která je označena ComUnregisterFunctionAttribute atributu se nazývá během proces zrušení registrace ke stornování operace způsob registrace.

Jak opravit porušení

Porušení tohoto pravidla odstranit, přidáte odpovídající registraci nebo rušení registrace metody.

Při potlačení upozornění

Nepotlačovat upozornění od tohoto pravidla.

Příklad

Následující příklad ukazuje typ, který porušuje pravidlo.S komentářem kód ukazuje oprava porušení.

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) {}
   }
}

Souvisejících pravidel

CA1411: Registrace metod modelu COM by neměl být viditelný

Viz také

Referenční dokumentace

Regasm.exe (sestavení registrační nástroj)

System.Runtime.InteropServices.RegistrationServices

Koncepty

Registrace sestavení s COM