I am trying to eliminate all the CLS-compliant errors that we have throughout out solution. While I have managed to sort out several (e.g. public variables beginning with an underscore and using unsigned integers), there are a few which I can't seem to find the reason why they are failing.
I have pasted the all the code relevant to one of the problems, there is a fair amount of code, but it only consists of a form constructor, interface and class that implements the interface.
VB.Net form constructor (the warning is on the unitOfWork
parameter and reads Type of parameter 'unitOfWork' is not CLS-compliant:
Public Sub New(ByRef unitOfWork As IUnitOfWork)
MyBase.New()
InitializeComponent()
_unitOfWork = unitOfWork
End Sub
The interface IUnitOfWork
is as follows:
public interface IUnitOfWork : IDisposable
{
bool IsInTransaction { get; }
bool IsDirty { get; }
object BeginTransaction();
object BeginTransaction(IsolationLevel isolationLevel);
void Commit();
void Rollback();
object Session { get; }
}
And the one and only implementation of the interface (and therefore the an instance of which will be passed to the form constructor) is this:
public class UnitOfWork : IUnitOfWork
{
private ISession _session;
public UnitOfWork(SMSession session)
{
if (session == null)
{
throw new ArgumentNullException("Session wasn't supplied");
}
this._session = (ISession)session.OpenSession();
}
public bool IsInTransaction
{
get { return this._session.Transaction.IsActive; }
}
public bool IsDirty
{
get { return this._session.IsDirty(); }
}
public object Session
{
get { return this._session; }
}
public object BeginTransaction()
{
return this._session.BeginTransaction(IsolationLevel.ReadCommitted);
}
public object BeginTransaction(IsolationLevel isolationLevel)
{
return this._session.BeginTransaction(isolationLevel);
}
public void Commit()
{
if (this._session.Transaction == null)
{
throw new NullReferenceException
("The Transaction has not been initialised");
}
this._session.Transaction.Commit();
}
public void Rollback()
{
if (this._session.Transaction == null)
{
throw new NullReferenceException
("The Transaction has not been initialised");
}
this._session.Transaction.Rollback();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
this._session.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
if (this._session != null)
{
this._session.Dispose();
}
Dispose(true);
GC.SuppressFinalize(this);
}
}
I am either being blind to the issue (could be the case as I have been staring at this for ages!) or there is another CLS-compliance restriction that I am unaware of. Any suggestions?
_unitOfWork
variableprivate
or is it another accessibility? When I had a similar issue in C# it was because I had aprotected
variable that started with_
. The CLS does not allow leading underscores in names that are exposed to other classes. – Trinref
parameters are compliant: #12598491 – AmandoSMSession
andISession
too? – LobectomyIUnitOfWork
doesn't touch those – ImmoderateIUnitOfWork
marked as CLS-compliant? – Immoderate