Quel est le problème avec le code suivant? Je ne peux pas voir la raison de l'erreur mentionnée ci-dessous. J'utilise Mono, cela pourrait-il être un bug dans Mono, et compilera-t-il sans erreurs dans VStudio?Pas de conversion de type boxe ou type pour le paramètre Type générique avec Mono
public static class ClientFactory {
public static T CreateClient<T, I>()
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(null, null);
}
public static T CreateClient<T, I>(string endpointConfigurationName)
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(endpointConfigurationName, null);
}
public static T CreateClient<T, I>(string endpointConfigurationName, string remoteAddress)
/* error here */
where T : ClientBase<I>, I
where I : class {
return CreateClient<T, I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password);
}
public static T CreateClient<T, I>(string endpointConfigurationName, string remoteAddress, string userName, string password)
/* NO error here, this method compiles fine */
where T : ClientBase<I>, I
where I : class {
T client;
/* get client instance */
/* do stuff with it */
return client;
}
}
Je reçois l'erreur de compilation:
…/ClientFactory.cs(14,14): Error CS0314: The type `T' cannot be used as type parameter `T' in the generic type or method `….ClientFactory.CreateClient(string, string)'. There is no boxing or type parameter conversion from `T' to `System.ServiceModel.ClientBase' (CS0314)
Je copiais votre code à un nouveau VC# 2010 projet, a changé '/ * faire des choses * /' à 'client = par défaut (T); 'et remplacé les deux paramètres par' "" '. Compile bien, aucune erreur de compilation. – dtb
Serait-ce un bug dans Mono? – knittl
Quelle version de 'dmcs' utilisez-vous? – dtb