Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a Service Hosted with windows authentication enabled and
trying to make a remote message call.
It is throwing an error, Saying
The type initializer for 'GlobalUSSFService.USSFService' threw an exception.

Pls do the needful.
Posted
Comments
Richard Deeming 21-Aug-14 9:46am    
You've been here over five years, asked over 40 questions in QA, and you still haven't worked out that we can't help you if you don't post the code?!

The exception message is clear: either the static constructor or a field initializer in the GlobalUSSFService.USSFService class threw an exception. You'll need to post the static constructor and field initializers of that class, along with the inner exception which tells you exactly what went wrong.
jagadeesh kumar adabala 22-Aug-14 2:42am    
Hi,
Thanks for the reply, and here is my class.

Imports System.DirectoryServices.AccountManagement
Imports System.Data.SqlClient

Partial Public Class USSFService
Implements ISFUser

'Private Shared SFUserId As String

'Private Shared SFUsersGroup As String = "ILHSPR"
'Private Shared SFAdminGroup As String = "Administrators"
'Private Shared SFSalesGroup As String = "TDSales"

Private Shared SFUsersGroup As String = "SOFTDEV"
Private Shared SFAdminGroup As String = "SOFTDEV"
Private Shared SFSalesGroup As String = "SOFTDEV"
Private Shared TDPrincipalContext As PrincipalContext = New PrincipalContext(ContextType.Domain, "XXXX")

Public Function GetAllProofReaders() As System.Collections.Generic.List(Of String) Implements ISFUser.GetAllProofReaders
Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(TDPrincipalContext, IdentityType.SamAccountName, SFUsersGroup)
Dim proofreaders As List(Of String) = New List(Of String)

For Each member As Principal In group.Members
If Not TypeOf member Is GroupPrincipal Then
If CType(member, UserPrincipal).Enabled Then proofreaders.Add(member.SamAccountName)
End If
Next
proofreaders.Sort()
Return proofreaders
End Function
End Class

i'm trying to access this method, which is working file when i host it locally.
But when i host it on a remote system and trying to call this method i got this exception.

and inner exception says 'Nothing'

Richard Deeming 22-Aug-14 7:53am    
If that's the full code of the class, then the only line that could cause a type initialization error is the New PrincipalContext(...) line. This would happen if the computer is not part of a domain, or the domain/server name "XXXX" is not valid.

The inner exception won't say "Nothing"; it will contain the exception that was thrown by the type initialization.

Also, please don't post large code blocks in the comments; use the "Improve question" link to update your question with the relevant code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900