Why SLAB SqlDatabaseSink stopped writing to Traces table?

404 views Asked by At

SLAB SqlDatabaseSink stopped writing to Traces table

I added a FlatFileSink in parallel to make sure the listener is not the issue, which writes fine to a file. I also have a Unit Test for the SqlDatabaseSink which works fine, but when subscribing from the main project via Global.asax only the FlatFileSink works. Screenshots below.

Added SLAB internal event listener per @manikrish 's suggestion (thank you very much for that), here is the underlying SQLDatabaseSink error from that log "Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'" - details below, SLAB Internal Log.

Next, I compared the reference properties of Newtonsoft.Json between main project and Unit Test project (who's SQLDatabaseSink works), both using version 6.0.8 (I believe WebApi 5.2.3 came with it), but noticed the Specific Version was False in the latter. So, I made the same change in the main project, still no luck.

Also, the main project's web.config and unit test project's app.config have the same assembly binding for it also:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>

Next, I tried addressing the binding redirect issue by changing reference properties in web.config, packages.config, csproj; reinstalling/updating the Newtonsoft.Json and also the calling assembly's (Microsoft.Practices.EnterpriseLibrary.SemanticLogging) NuGet package based on other stackoverflow questions (links below), still no luck - same binding error in the SLAB Internal Log, there is no evidence of my biding redirect.

SLAB Internal Log:

Opcode : Info
Task : 65433
Version : 0
Payload : [message : System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming)
   at System.Data.SqlClient.SqlParameter.GetCoercedValue()
   at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
   at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
   at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(AsyncCallback callback, Object stateObject, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory`1.FromAsync(Func`3 beginMethod, Func`2 endMethod, Object state)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<>c__DisplayClass14.<<UseStoredProcedure>b__13>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<UseStoredProcedure>d__1d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<PublishEventsAsync>d__0.MoveNext()

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/work/StarLims/AMO/server/TFS/AMO/eyeNet/AI.eyeNet/
LOG: Initial PrivatePath = C:\work\StarLims\AMO\server\TFS\AMO\eyeNet\AI.eyeNet\bin
Calling assembly : Microsoft.Practices.EnterpriseLibrary.SemanticLogging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\work\StarLims\AMO\server\TFS\AMO\eyeNet\AI.eyeNet\web.config
LOG: Using host configuration file: C:\Users\siliodx\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/74a40fb9/3b0c98c/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/74a40fb9/3b0c98c/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/work/StarLims/AMO/server/TFS/AMO/eyeNet/AI.eyeNet/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
] 
EventName : DatabaseSinkPublishEventsFailedInfo
Timestamp : 2015-06-05T11:56:54.5518724Z
ProcessId : 6752
ThreadId : 12060

StackOverflow supporting links:

Infamous assembly binding error

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference

Newtonsoft.Json.dll issue when using multiple projects

Assembly mismatch despite having assembly redirect and loading correct version

Screenshots: Global.asax SLAB configuration call

SLAB configuration

NuGet SLAB packages in the project

2

There are 2 answers

0
siliond On BEST ANSWER

The root cause was a missing dependentAssembly tag around one of the assemblies in web.config:

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

Thank you very much to Mani and the other SLAB team members that helped me, especially since the root cause had nothing to do with their project.

4
manikrish On

The Semantic logging application block logs internal events to a pre-defined event source called the SemanticLoggingEventSource. You could create an additional listener which logs the events from this event source to a different sink.

For example, the snippet below shows how to log internal events to a file:

var slabInternalNotificationsListener = new ObservableEventListener();
slabInternalNotificationsListener.LogToFlatFile(@".\errors.txt");
slabInternalNotificationsListener.EnableEvents(SemanticLoggingEventSource.Log, System.Diagnostics.Tracing.EventLevel.Verbose, Keywords.All);

Please take a look at the logs from the SemanticLoggingEventSource to see why the SQL sink is not logging events.