Home Help Center

CLS in class library of C#

changchang Member shen changOrganization: nasaProject: AMO HDU ✭✭
This is a newbie question:

CLS for ice in class library

Hi All
I have a very simple ice file t.ice for test. I got CLS error depends where I put this ice file. Here is the story
First, I made a class library project tlib and put t.ice file there (this way, I thought I can better manage all ice files and let others just use library). Then in the project, I reference to the library tlib. In the project I have a class tttI as below.

module T
sequence<double> sDouble;
struct Txd{
sDouble reals;
interface ttt{
void transfer(Txd message);

// in the using project , it refer to Tlib project
using T;
public class tttI : tttDisp_
public override void transfer(Txd m, Current current)
string s = m.reals.ToString();

This give me error as:
Error 1 Warning as Error: 'Subscriber.App.tttI': base type 'T.tttDisp_' is not CLS-compliant
Error 2 Warning as Error: Argument type 'T.Txd' is not CLS-compliant

But if I move this t.ice file into the project instead of using the class library. No other things are changed . There is no error this time !

To be short, when the ice file is in another class library project, C# compiler gives error when to compile the project using that class library, if the ice file is in the same project, C# does not give error.

C Shen


  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Shen

    Ice generated code is CLS compliant, but assemblies are by default not compliant unless you mark the as compliant.

    To avoid this warnings, you can mark the whole library as CLS compliant, in your library AssemblyInfo.cs add the following attribute.

    When the generate code is in the application .NET don't check this, that is a check for assembly be compatible with other CLR languages.

    Also note that this is just a warning and your project produce an error because you have "Treat warnings as errors" enabled.

    See also Mark assemblies with CLSCompliant
Sign In or Register to comment.