jestem otrzymaniu FaultException z usługi WCF w następujący sposób przy wywołaniu:TypeInitializationException: Typ inicjator dla „vService.CheckService” zwrócił wyjątek
2012-04-02 16:26:00.3593|Error|System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The type initializer for 'vService.CheckService' threw an exception. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.TypeInitializationException: The type initializer for 'vService.CheckService' threw an exception. ----> System.NullReferenceException: Object reference not set to an instance of an object.
at vService.CheckService..cctor() in d:\working\code\VioletServer\vService\CheckService.cs:line 14
--- End of inner ExceptionDetail stack trace ---
at vService.CheckService..ctor()
at CreatevService.CheckService()
at System.ServiceModel.Dispatcher.InstanceProvider.GetInstance(InstanceContext instanceContext, Message message)
at System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance(InstanceContext instanceContext, Message request)
at System.ServiceModel.InstanceContext.GetServiceInstance(Message message)
at System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
...).
Linia 14 CheckService.cs jest
private static string connStr = ConfigurationManager.ConnectionStrings["violetdb"].ConnectionString;
Co oznacza wyjątek w tym kontekście i jak mogę go rozwiązać?
//CheckService.cs
public class CheckService : ICheckService
{
private static string connStr = ConfigurationManager.ConnectionStrings["violetdb"].ConnectionString;
MessageRepository _repo = new MessageRepository(connStr);
public CheckService(){}
public CheckService(MessageRepository repo)
{
_repo = repo;
}
public void SendMessage(string sender, string recipient, string messagetext)
{
_repo.DeliverMessage(sender,recipient,messagetext);
}
}
Posiadałem ciąg połączenia 'violetdb' w sekcji' 'w pliku' web.config'. Ponieważ projekt jest biblioteką klas, właśnie dodałem plik 'app.config' i skopiowałem ciąg połączenia. Nadal mam wyjątek. –
Animesh
Gdzie udostępniasz swoją aplikację? Czy jest on hostowany (tzn. Aplikacja konsolowa lub usługa systemu Windows? Czy jest hostowana w IIS? –
Jest hostowana w aplikacji konsolowej: – Animesh