3

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    This bit of code is valid. I put in a basic console application with a derived class. Are you sure you are putting everything here that causes the error? How about the derived class? How do you know this is the bit that caused the problem? – Styxxy Feb 09 '13 at 23:48
  • 1
    Is this really the class, *as-is in your code*? I doubt it. There’s nothing which violates CLS compliance here. – Konrad Rudolph Feb 09 '13 at 23:49
  • Yes - that is the complete code. I pasted in the complete text of the file itself, for both base and derived classes. I get a compiler warning which says: "Warning 1 'SystemValueModel' is not CLS-compliant because it derives from 'BaseModel', which is not CLS-compliant.' –  Feb 10 '13 at 00:26
  • 1
    Taking the classes in a single Console Application it still perfectly builds... It is not the code that you post here that is the problem. There is something else causing the problem. – Styxxy Feb 10 '13 at 00:44
  • Thanks for the feedback and looking at it for me. I appreciate it. –  Feb 10 '13 at 02:33

1 Answers1

0

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.

Jim Hewitt
  • 1,726
  • 4
  • 24
  • 26