尝试从 WCF 服务调用方法时出现类型初始化错误。
'XYZAuditService' 的类型初始化程序引发了异常。
但是,我在代码中看不到任何会导致异常的内容。
public enum AuditProcessType
{
Facility,
Patient,
Report,
}
[ServiceBehavior(Name = "AuditService",
Namespace = "http://xyz/services/2008/08",
InstanceContextMode = InstanceContextMode.PerSession,
ConcurrencyMode = ConcurrencyMode.Single)]
public class AuditService : IAuditServiceContract
{
private static Dictionary<AuditProcessType, Func<IAuditor>> auditServiceFactories;
static AuditService()
{
auditServiceFactories = new Dictionary<AuditProcessType, Func<IAuditor>>()
{
{ AuditProcessType.Facility, () => Auditor<Facility>.Instance },
{ AuditProcessType.Patient, () => Auditor<Patient>.Instance },
{ AuditProcessType.Report, () => Auditor<Report>.Instance },
};
}
// ...
private static IAuditor GetAuditor(AuditProcessType process)
{
Func<IAuditor> factory;
if (!auditServiceFactories.TryGetValue(process, out factory) || factory == null)
{
throw new ArgumentException(..., "process");
}
IAuditor auditor = null;
try
{
auditor = factory();
}
catch (Exception ex)
{
throw new InvalidOperationException(..., ex);
}
if (auditor == null)
{
throw new InvalidOperationException(...);
}
return auditor;
}
}
public class Auditor<T> : IAuditor
{
private static Auditor<T> _instance = new Auditor<T>();
public static Auditor<T> Instance
{
get
{
return _instance;
}
}
private Auditor()
{
}
// ...
}
我的日志框架没有显示任何内部异常细节,所以我无法获得比这更多的信息。无论我尝试了什么,我似乎都无法让 VS 调试器在类型初始化程序中停止。不过,我看不出这段代码是如何引发异常的。我的代码本身除了初始化工厂字典之外什么都不做,它甚至不调用AuditService<T>.Instance
. 还有什么可能导致这种情况?