Why is my class not CLS compliant?

It really puzzles me. I tried to remove readonly by changing names .. What am I doing wrong here?

public abstract class CatalogBase<T> where T : class { protected readonly String DataPath; protected readonly XmlSerializer Serializer; private readonly XmlSerializerNamespaces _namespaces; protected CatalogBase(String dataPath) { DataPath = dataPath; Serializer = new XmlSerializer(typeof (T)); _namespaces = new XmlSerializerNamespaces(); _namespaces.Add(String.Empty, String.Empty); } public virtual void Write(T obj) { var streamWriter = new StreamWriter(DataPath); Serializer.Serialize(streamWriter, obj, _namespaces); streamWriter.Close(); } public abstract IDictionary<String, T> Read(); } 

Edit:

A warning:

Warning 1 'Ar.ViewModel.Workspaces.MaterialCatalogBase': base type "Or.Files.CatalogBase" not CLS-compatible C: _Center_Work_Programming_Cs \ Ar \ Ar \ ViewModel \ Workspaces \ MaterialCatalogBase.cs 9 18 Ar

Edit2:

Even if I change the class as shown below, I still get the error:

 public abstract class CatalogBase<T> where T : class { protected readonly String DataPath; protected readonly XmlSerializer Serializer; private readonly XmlSerializerNamespaces namespaces; protected CatalogBase(String dataPath) { DataPath = dataPath; Serializer = new XmlSerializer(typeof (T)); namespaces = new XmlSerializerNamespaces(); namespaces.Add(String.Empty, String.Empty); } public virtual void Write(T obj) { var streamWriter = new StreamWriter(DataPath); Serializer.Serialize(streamWriter, obj, namespaces); streamWriter.Close(); } public abstract IDictionary<String, T> Read(); } 

Also, I forgot to mention that for some reason I get two (exactly the same errors).

+7
source share
1 answer

It looks like you have the following:

  • Assembly A announces CatalogBase<T> . Assembly A not marked as CLSCompliant
  • Assembly of assembly MaterialCatalogBase : CatalogBase<T> collections A. Assembly B declares MaterialCatalogBase : CatalogBase<T> . Assembly B marked as CLSCompliant

If this is your case, then the assembly in which your CatalogBase<T> class is located should be marked with the CLSCompliant attribute:

 [assembly: CLSCompliant(true)] 
+4
source

All Articles