Question

What is not CLS compliant about the simple class below?

I get the warning that my derived class is not CLS compliant, because it inherits from the class below, which is not CLS compliant (apparently).

Public MustInherit Class BaseModel

    Protected MustOverride Sub SetIDValue(nValue As Long)

End Class

Yes - the above is the full code of the class.

Here are full files for both the base class and derived class:

Base class:

Imports System.ComponentModel.DataAnnotations

Namespace Core

    Public MustInherit Class BaseModel

        Protected MustOverride Sub SetIDValue(nValue As Long)

    End Class

End Namespace

Derived class:

Imports Snap.Core
Imports System.ComponentModel.DataAnnotations


Public Class SystemValueModel
    Inherits BaseModel

    Public Sub New()

    End Sub


    Public ID_SystemValue As Long

    <Required()> <StringLength(25)>
    Public Token As String

    <Required()> <StringLength(255)>
    Public Value As String

    Protected Overrides Sub SetIDValue(nValue As Long)
        'Nada
    End Sub

End Class

No correct solution

OTHER TIPS

I was able to reproduce this error by Enabling Code Analysis on Build and using "Microsoft All Rules". To mark BaseModel as CLS Compliant, add <Assembly: CLSCompliant(True)> before Namespace Core You can find more information here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top