Well, what would you do with the Detail if you knew it's type anyway?
Because it's generic you would have to have a generic method and use MethodInfo.MakeGenericMethod using the T of the FaultException as the generic parameter. Since you won't know exactly what type it is at compile time, you'd have to code against it generically in some sense anyway.
As an example, here's a method I wrote to log fault details:
private static void WriteGenericFaultExceptionDetail<T>(FaultException faultException, StringBuilder faultDetailsBuilder)
{
FaultException<T> faultExceptionWithDetail = (FaultException<T>)faultException;
DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T));
using(StringWriter writer = new StringWriter(faultDetailsBuilder))
using(XmlWriter xmlWriter = XmlWriter.Create(writer))
{
dataContractSerializer.WriteObject(xmlWriter, faultExceptionWithDetail.Detail);
}
}
And then I call it like so:
// NOTE: I actually cache this in a static field to avoid the constant method lookup
MethodInfo writeGenericFaultExceptionDetailMethodInfo = typeof(MyClass).GetMethod("WriteGenericFaultExceptionDetail", BindingFlags.NonPublic|BindingFlags.Static);
Type faultExceptionType = myFaultException.GetType();
writeGenericFaultExceptionDetailMethodInfo.MakeGenericMethod(faultExceptionType.GetGenericArguments()).Invoke(null, new object[] { myFaultException, myTraceBuilder })