Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Type Initializer error means that the type couldn't be created. This happens before the call to the constructor when the CLR initialized all the static fields. Since your initialization does something more than call a private constructor or set a literal value you're opening yourself up to difficult to debug problems</p> <p>In this case its likely do to a problem with one of your AppSettings keys </p> <p>e.g.</p> <pre><code>private static string smtpServer = ConfigurationManager.AppSettings["smtpServer"]; private static string sendTo = ConfigurationManager.AppSettings["sendTo"]; ... </code></pre> <p>This looks suspicious as well.</p> <pre><code>private static SPWeb _Web = new SPSite(portalURL).OpenWeb(); private static NETRESOURCE res = new NETRESOURCE(); </code></pre> <p>Instead do what you need to do in the constructor. You might also want to add a helper method so that way you can raise a better exception (or instead you could as Marc Gravel comments just look at the Inner Exception)</p> <p>For example </p> <pre><code> private string safeGetAppSetting(string key) { try { return ConfigurationManager.AppSettings["smtpServer"]; } catch(ConfigurationErrorsException) { throw new InvalidOperationException(string.Format("key {0} is missing or misconfigured", key); } } public cisf_UploaderService() { InitializeComponent(); smtpServer = safeGetAppSetting("smtpServer"); } </code></pre> <p><strong>Update</strong> In hindsight adding Debugger.Launch() to Program.Main() as kzen mentioned may be worthwhile. If its not a local dev machine that's the issue adding some additional logging at the root may help as well. </p> <pre><code> try { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SampleWindowsService() }; ServiceBase.Run(ServicesToRun); } catch (Exception ex) { string SourceName = "YourService.ExceptionLog"; if (!EventLog.SourceExists(SourceName)) { EventLog.CreateEventSource(SourceName, "Application"); } EventLog eventLog = new EventLog(); eventLog.Source = SourceName; string message = ""; if (ex.InnerException != null) string message = string.Format("Exception: {0} \n\nStack: {1} \n\nInnerException: {2}", ex.Message, ex.StackTrace, ex.InnerException.Message); else string message = string.Format("Exception: {0} \n\nStack: {1}", ex.Message, ex.StackTrace); eventLog.WriteEntry(message, EventLogEntryType.Error); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload