VS2005: non CLS-compliant classes

O

Oenone

I am currently in the process of upgrading my VB.NET applications and DLLs
from VS2003 to VS2005. Everything seems to be going fine, but I've had a
couple of warnings that I don't understand.

In one of my DLLs I define a MustInherit base class with various properties
and methods. In another DLL I inherit from that class to create a custom
derived class. I am getting the following warning in the IDE:

'DerivedClass' is not CLS-compliant because it derives from 'BaseClass',
which is not CLS-compliant.

No warnings are displayed at all for BaseClass. How can I determine what
exactly is it about BaseClass that stops it from being CLS-compliant?

For reference, I have Option strict On for the base class, and within its My
Project settings, I have all of the Compile Conditions set to either Error
or Warn except for "Use of variable prior to assignment" and
"Function/Operator without return value". Could it be one of these that is
causing the non-CLS-compliance issues to occur?

Many thanks,
 
G

Guest

Not sure exactly what you're seeing. I tried the following as a test, and it
compiles without warning:

Public Class b
Inherits A

Public Overrides Sub foo()

End Sub
End Class

Public MustInherit Class A
Public MustOverride Sub foo()

End Class
 
J

Jay B. Harlow [MVP - Outlook]

Oenone,
Do you have CLSCompliant attribute in your AssemblyInfo.vb file?

Is it set to True or False?

<Assembly: CLSCompliant(True)>

Do you have a CLSCompliant set to false on the base class?

I would expect a warning on the base class...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|I am currently in the process of upgrading my VB.NET applications and DLLs
| from VS2003 to VS2005. Everything seems to be going fine, but I've had a
| couple of warnings that I don't understand.
|
| In one of my DLLs I define a MustInherit base class with various
properties
| and methods. In another DLL I inherit from that class to create a custom
| derived class. I am getting the following warning in the IDE:
|
| 'DerivedClass' is not CLS-compliant because it derives from
'BaseClass',
| which is not CLS-compliant.
|
| No warnings are displayed at all for BaseClass. How can I determine what
| exactly is it about BaseClass that stops it from being CLS-compliant?
|
| For reference, I have Option strict On for the base class, and within its
My
| Project settings, I have all of the Compile Conditions set to either Error
| or Warn except for "Use of variable prior to assignment" and
| "Function/Operator without return value". Could it be one of these that is
| causing the non-CLS-compliance issues to occur?
|
| Many thanks,
|
| --
|
| (O)enone
|
|
 
O

Oenone

Jay said:
Oenone,
Do you have CLSCompliant attribute in your AssemblyInfo.vb file?

I didn't, but I added it to the AssemblyInfo for the project that provides
the base class.

It added another warning, telling me that one of the classes referred to a
class in a referenced DLL that was also not CLSCompliant (though I have no
idea why, it's a simple collection-style class that inherits from
System.Collections.CollectionBase).

I added the CLSCompliant attribute to that assembly too, and without any
further changes, all the warnings have now gone away.

Which is good, but means I still don't understand what the original issue
is...

Why is this attribute not applied to AssemblyInfo.vb by default?
 
J

Jay B. Harlow [MVP - Outlook]

Oenone,
Although VB 2002 & 2003 allowed you to include the CLSCompliant attribute it
didn't use the attribute, so the attribute was not included...

VB 2005 now uses the attribute & will report errors/warnings based on it. If
the attribute is missing, False is assumed.

http://msdn2.microsoft.com/en-us/library/ms182156.aspx


NOTE: You can include it on anything you want, not just an assembly.

http://msdn2.microsoft.com/en-us/library/ck7ah248(en-US,VS.80).aspx

For example I normally mark the assembly as CLSCompliant(True) while I may
make certain types or type members as CLSCompliant(False), such as members
that use non compliant COM interop classes... Due to Encapsulation exposing
non compliant COM interop classes is probably a bad idea anyway as it
increases coupling...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Jay B. Harlow [MVP - Outlook] wrote:
| > Oenone,
| > Do you have CLSCompliant attribute in your AssemblyInfo.vb file?
|
| I didn't, but I added it to the AssemblyInfo for the project that provides
| the base class.
|
| It added another warning, telling me that one of the classes referred to a
| class in a referenced DLL that was also not CLSCompliant (though I have no
| idea why, it's a simple collection-style class that inherits from
| System.Collections.CollectionBase).
|
| I added the CLSCompliant attribute to that assembly too, and without any
| further changes, all the warnings have now gone away.
|
| Which is good, but means I still don't understand what the original issue
| is...
|
| Why is this attribute not applied to AssemblyInfo.vb by default?
|
| --
|
| (O)enone
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top