I know and I think I understand about the (co/conta)variance issue with IEnumerables. However I thought the following code would not be affected by it.
[DataContract]
public class WcfResult<T>
{
public WcfResult(T result)
{
Result = result;
}
public WcfResult(Exception error)
{
Error = error;
}
public static implicit operator WcfResult<T>(T rhs)
{
return new WcfResult<T>(rhs);
}
[DataMember]
public T Result { get; set; }
[DataMember]
public Exception Error { get; set; }
}
This class is to mimic BackgroundWorker's RunWorkerCompletedEventArgs so I can return errors from my WCF service without faulting the connection.
Most of my code is working fine so I can do things like this
public WcfResult<Client> AddOrUpdateClient(Client client)
{
try
{
//AddOrUpdateClient returns "Client"
return client.AddOrUpdateClient(LdapHelper);
}
catch (Exception e)
{
return new WcfResult<Client>(e);
}
}
and it works fine, however the folowing code gives a error
public WcfResult<IEnumerable<Client>> GetClients(ClientSearcher clientSearcher)
{
try
{
//GetClients returns "IEnumerable<Client>"
return Client.GetClients(clientSearcher, LdapHelper, 100);
}
catch (Exception e)
{
return new WcfResult<IEnumerable<Client>>(e);
}
}
Where the error is
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<myNs.Client>'
to 'myNs.WcfResult<System.Collections.Generic.IEnumerable<myNs.Client>>'. An explicit
conversion exists (are you missing a cast?)
What is going wrong that is causing this error to happen?
Foo<List<A>>
for testing! – Antananarivo