CLS compliance and custom types

S

steve bull

I have created a class with get/set methods but VS complains that the type of the variable is not CLS compliant. For example in the
following code :

namespace TilerSpace
{
public partial class TilerGoldenTriangleDEPanel : Form
{

public SwatchType PlusFilter
{
get
{
return scbxPlusDEColor.SwatchTypeList;
}
set
{
scbxPlusDEColor.SwatchTypeList = value;
}

} /* End of property PlusFilter */
}

I get a compiler warning "Type of PlusFilter is not CLS compliant".



SwatchType is a type declared in a seperate dll but included as a reference in the solution. Originally the dll was part of the
solution, though a separate project, and I didn't get this problem. Now having moved the code off to it's own dll I don't seem to be
able to get rid of the problem. Except, possibly, making it part of the solution again.

I could disable CLS compliance but I don't really want to do that. The application would always need to include the dll. Why should
this be a problem? I could include SwatchType variables in any other part of the code w/o getting a warning. Is there something
special about get/set or am I looking at this wrong way.


Thanks,

Steve
 
S

steve bull

SwatchType is an enum but I don't think that is important. If I were to change it to bool or int the compiler would be happy. I have
various get/set properties. All the ones defined external to the project, be it an enum or a class type, are flagged as not being
CLS compliant.
 
G

GlennDoten

steve said:
SwatchType is an enum but I don't think that is important. If I were to change it to bool or int the compiler would be happy. I have
various get/set properties. All the ones defined external to the project, be it an enum or a class type, are flagged as not being
CLS compliant.

Well what is the underlying type of the enum. If it is unsigned then
you'll get the not CLS compliant message.
 
G

GlennDoten

steve said:
I have created a class with get/set methods but VS complains that the type of the variable is not CLS compliant. For example in the
following code :

namespace TilerSpace
{
public partial class TilerGoldenTriangleDEPanel : Form
{

public SwatchType PlusFilter
{
get
{
return scbxPlusDEColor.SwatchTypeList;
}
set
{
scbxPlusDEColor.SwatchTypeList = value;
}

} /* End of property PlusFilter */
}

I get a compiler warning "Type of PlusFilter is not CLS compliant".



SwatchType is a type declared in a seperate dll but included as a reference in the solution. Originally the dll was part of the
solution, though a separate project, and I didn't get this problem. Now having moved the code off to it's own dll I don't seem to be
able to get rid of the problem. Except, possibly, making it part of the solution again.

I could disable CLS compliance but I don't really want to do that. The application would always need to include the dll. Why should
this be a problem? I could include SwatchType variables in any other part of the code w/o getting a warning. Is there something
special about get/set or am I looking at this wrong way.


Thanks,

Steve

Two guesses.

1. SwatchType is unsigned.
2. The project that uses this type does not have [CLSCompliant(true)] at
the assembly level.

So would need to know the type of SwatchType and if CLSCompliant is in
all of the mentioned projects or not.
 
S

steve bull

Thanks, I had my main application set as CLS compliant but not the library that it called. Once I marked the librar as cls compliant
in AssemblyInfo the problem disappeared.

SwatchTYpe was declared as :


[Flags]
public enum SwatchType
{
None = 0x0000,
DoNotDraw = 0x0001,
SystemColor = 0x0002,
CustomColor = 0x0004,
ColorRange = 0x0008,
HueRange = 0x0010,
Shade = 0x0020,
HatchBrush = 0x0040,
Gradient = 0x0080,
All = 0x00FF,
EdgeColor = 0x003F

} /* End of enum SwatchTypes */


Thanks again,

Steve




steve said:
I have created a class with get/set methods but VS complains that the type of the variable is not CLS compliant. For example in the
following code :

namespace TilerSpace
{
public partial class TilerGoldenTriangleDEPanel : Form
{

public SwatchType PlusFilter
{
get
{
return scbxPlusDEColor.SwatchTypeList;
}
set
{
scbxPlusDEColor.SwatchTypeList = value;
}

} /* End of property PlusFilter */
}

I get a compiler warning "Type of PlusFilter is not CLS compliant".



SwatchType is a type declared in a seperate dll but included as a reference in the solution. Originally the dll was part of the
solution, though a separate project, and I didn't get this problem. Now having moved the code off to it's own dll I don't seem to be
able to get rid of the problem. Except, possibly, making it part of the solution again.

I could disable CLS compliance but I don't really want to do that. The application would always need to include the dll. Why should
this be a problem? I could include SwatchType variables in any other part of the code w/o getting a warning. Is there something
special about get/set or am I looking at this wrong way.


Thanks,

Steve

Two guesses.

1. SwatchType is unsigned.
2. The project that uses this type does not have [CLSCompliant(true)] at
the assembly level.

So would need to know the type of SwatchType and if CLSCompliant is in
all of the mentioned projects or not.
 

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

Similar Threads


Top