I am trying to create a feature that Extends the SPDiagnosticServicesBase class following the code described in MSDN That article has example code for extending the SPDiagnosticServicesBase class which I am using almost verbatim.
Luckily, my solution deploys properly and I am able to see my custom categories in Central Administration Diagnostic Logging page.
However, in a second WebPart solution I am building I want to use this dll to write log statements using my extended SPDiagnosticServices class: MyDiagnosticServices
When my WebPart solution references the Local method to write a trace log like:
MyDiagnosticService.Local.LogMessage(...)
The Local() method of MyDiagnosticService class fails with the following Error
System.InvalidCastException was unhandled by user code
Message=Unable to cast object of type 'MyDiagnosticService.MyDiagnosticService' to type 'MyDiagnosticService.MyDiagnosticService'.
Source=Microsoft.SharePoint
StackTrace:
at Microsoft.SharePoint.Administration.SPPersistedObjectCollection`1.GetValue[U](String name)
at Microsoft.SharePoint.Administration.SPPersistedObjectCollection`1.GetValue[U]()
at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)
at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()
at SJHSDiagnosticService.SJHSDiagnosticService.get_Local()
at SJHSMinistryRedirect.SJHSMinistryRedirect.SJHSMinistryRedirectUserControl.<>c__DisplayClass4.<_eventLogWrite>b__0()
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
InnerException:
Thank you for your advise on how to fix this error.