C# Blazor - Fix "This connection was used with an ambient transaction..." - c#

I added a timer in a Blazor page, so some data (pulled from database) can refresh every 5 seconds. It works fine when I'm on the page, but when I move to a different page and come back to the original one, I get this error:
"This connection was used with an ambient transaction. The original
ambient transaction needs to be completed before this connection can
be used outside of it" I've included the stack trace at the end
I've tried to dispose the Timer when the page disposes, but it didn't solve it. It looks like this issue is due to how the DB context is registered in the Dependency Injection container, but
Here is the C# code of my page. It calls the main service, who in turns gets data through a repository.
#functions {
protected Dictionary<int, int> RunningTaskProcessQueueCountDictionary;
protected Dictionary<int, int> PendingTaskProcessQueueCountDictionary;
protected Timer CountRefreshTimer = null;
protected override async Task OnInitAsync()
{
CountRefreshTimer = new Timer(new TimerCallback(async _ =>
{
await RefreshCount();
await base.Invoke(StateHasChanged);
}), null, 0, 5000);
}
private async Task RefreshCount()
{
RunningTaskProcessQueueCountDictionary = await mainService.GetRunningTaskProcessQueueCountByTaskAppAsync(null);
PendingTaskProcessQueueCountDictionary = await mainService.GetPendingTaskProcessQueueCountByTaskAppAsync(null);
}
public void Dispose()
{
if (CountRefreshTimer != null)
{
CountRefreshTimer.Dispose();
}
}
}
Here is an extract of the startup.cs where DB context is registered:
// Register the DB Context
var connection = Configuration.GetConnectionString("SQL01.xxx");
services.AddDbContext<SQL01xxxContext>(options => options.UseSqlServer(connection));
// Register all repositories and services (using Scrutor)
services.Scan(scan =>
scan.FromAssemblies(typeof(IMainService).Assembly, typeof(ITaskAppRepository).Assembly)
.AddClasses()
.AsMatchingInterface()
.WithScopedLifetime());
services.AddScoped<DbContext, SQL01xxxContext>();
services.AddScoped<IUnitOfWork<SQL01xxxContext>, UnitOfWork<SQL01xxxContext>>();
This is the stacktrace of the error
System.InvalidOperationException HResult=0x80131509 Message=This
connection was used with an ambient transaction. The original ambient
transaction needs to be completed before this connection can be used
outside of it. Source=Microsoft.EntityFrameworkCore.Relational
StackTrace: at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.HandleAmbientTransactions()
at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.d__42.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.d__12.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.<ExecuteAsync>d__72.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.d__11.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at
System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator2.d__7.MoveNext()
in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Select.cs:line 106
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at
System.Linq.AsyncEnumerable.AsyncIterator1.d__10.MoveNext()
in
D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line
112 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at System.Linq.AsyncEnumerable.d__63.MoveNext()
in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line
120 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
SIQC.Enterprise.GenericRepository.Common.IQueryableExtensions.d__11.MoveNext()
in C:\TFS\[...]\IQueryableExtensions.cs:line 28 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
SIQC.Enterprise.GenericRepository.RepositoryBase.ReadOnlyRepository1.<GetAsync>d__12.MoveNext()
in C:\TFS\[...]\ReadOnlyRepository.cs:line 174 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
ToolsWebManagementData.IntravexV21.Repository.TaskProcessQueueRepository.d__2.MoveNext()
in C:\TFS[...]\TaskProcessQueueRepository.cs:line 46 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
TWMBlazorSSB.Services.MainService.<GetRunningTaskProcessQueueCountByTaskAppAsync>d__21.MoveNext()
in C:\TFS\[...]\MainService.cs:line 79 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at TWMBlazorSSB.Pages.TaskApp.TaskApps.d__7.MoveNext()
in C:\TFS[...]\TaskApps.razor:line 91 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at
TWMBlazorSSB.Pages.TaskApp.TaskApps.<b__6_0>d.MoveNext()
in C:\TFS[...]\TaskApps.razor:line 79
Any help would be appreciated.
Thanks

It looks like this issue is due to how the DB context is registered
That is correct. This is because AddDbContext<> uses (as default) ServiceLifetime.Scoped. But there is no useful Scope.
This is still under discussion by the Blazor team, maybe wait for the next preview before considering a workaround.
But I see it is now bumped to preview-9.

Related

WEB API: The client disconnected [duplicate]

I'm getting the following error in logs for WebAPI
System.Web.HttpException (0x800703E3): The client disconnected. at
System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult)
at System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult
asyncResult) at System.Threading.Tasks.TaskFactory
1.FromAsyncTrimPromise 1.Complete(TInstance thisRef, Func 3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- 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 System.IO.StreamReader.d__97.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
System.IO.StreamReader.d__62.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.Owin.OwinRequest.d__0.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.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__22.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.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__0.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.Owin.Security.Infrastructure.AuthenticationMiddleware
1.d__0.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 Web.API.Middleware.OwinMiddleware.d__1.MoveNext()
in D:\UAT\Web.API\Middleware\OwinMiddleware.cs:line 49
How can I handle and ignore these exceptions by exception filter? Why this error occurs and how can I reproduce that? I wanna catch and ignore only The client disconnected but not all HttpException
I saw this similar question but how can I do that in exception filter?
You can ignore these exceptions.
The exception says what the problem is: "The client disconnected". It means that the client initiated a request but then disconnected before it bothered to read all of the response.
There are any numbers of reasons why that might be the case, but (unless you have a dodgy internet connection at your server end) it is almost certainly an issue at the client end. I regularly see these myself and mostly it seems to be related to a bot. So I filter them out and ignore them.
try
{
// Open Connection
// Do stuff
}
catch (HttpException ex)
{
// Log it?
// Ignore it?
// Do what you want with it?
}
finally
{
// Close connection
}

Can not find compilation library location for package 'Newtonsoft.Json'

Using Visual Studio for Mac (Community 7.3), I am trying to run the sample project from Lynda.com's "Learning ASP.NET Core MVC" Chapter 3 which introduces "Render HTML with Razor".
I builds find but when I try to load in browser I get the error below:
An unhandled exception occurred while processing the request.
InvalidOperationException: Can not find compilation library location
for package 'Newtonsoft.Json'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Stack Query Cookies Headers InvalidOperationException: Can not find
compilation library location for package 'Newtonsoft.Json'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
System.Linq.Enumerable+d__157.MoveNext()
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable
parts, MetadataReferenceFeature feature)
Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature(TFeature
feature)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.GetCompilationReferences()
System.Threading.LazyInitializer.EnsureInitializedCore(ref T
target, ref bool initialized, ref object syncLock, Func
valueFactory)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.get_CompilationReferences()
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.Compile(RelativeFileInfo
fileInfo, string compilationContent)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry(string
relativePath, string normalizedPath, Func compile)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.GetOrAdd(string
relativePath, Func compile)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(string
relativePath)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet
expirationTokens, string relativePath, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext
expanderContext, ViewLocationCacheKey cacheKey)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext
actionContext, string pageName, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext
context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext
context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor.FindView(ActionContext
actionContext, ViewResult viewResult)
Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__32.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__31.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__29.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__23.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
ExploreCalifornia.Startup+<>c+<b__3_0>d.MoveNext() in
Startup.cs
await next(); System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__6.MoveNext()
Show raw exception details

A task was cancelled error in context.postAsync() and while sending the typing activity Bot Framework

I am getting the task was cancelled error intermittently in two lines of code.
Code Example
await connector.Conversations.ReplyToActivityAsync(isTypingReply);
and
await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
Reproduction Steps
Happens intermittently, not able to reproduce on will
Actual Results
Getting below errors in the mentioned lines of code
Time: 04-12-2017 12:15:11 PM
Message: A task was canceled.
Stack Trace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Conversations.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.ConversationsExtensions.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ParentServiceContoller.MessagesController.d__4.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Controllers\MessagesController.cs:line 34
Source: mscorlib
Time: 04-12-2017 12:44:56 PM
Message: A task was canceled.
Stack Trace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Conversations.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.ConversationsExtensions.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.InputHintQueue.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.AutoInputHint_BotToUser.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.MapToChannelData_BotToUser.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.LogBotToUser.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Extensions.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ParentServiceContoller.Dialogs.RegistrationDialog.d__11.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Dialogs\RegistrationDialog.cs:line 216
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Wait2.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Frame1.-PollAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter.GetResult() at ParentServiceContoller.Dialogs.RootDialog.d__9.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Dialogs\RootDialog.cs:line 211 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.-PollAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.-PollAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d__172.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.d__18`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ParentServiceContoller.Dialogs.RootDialog.d__8.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Dialogs\RootDialog.cs:line 182
Source: mscorlib
Got it working, the issue was due to DNS. When we do context.PostAsync() then a new task is created which tries to send the message to the user, but before that it needs to resolve the DNS of the service URL. In some cases the DNS takes more time in responding and the task time out thus cancels itself, which is the reason why the issue was intermittent. Retrying context.PostAsync() in case of task cancelled exception does the job other than moving to paid DNS.
you can use the below code:
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity isActivityTyping = activity.CreateReply();
isActivityTyping.Type = ActivityTypes.Typing;
await connector.Conversations.ReplyToActivityAsync(isActivityTyping);
then use
await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
i hope this will help you out.
do let me know in case of more help required.

Task Canceled exception on RavenDB when creating indexes

I'm having an issue trying to create indexes on RavenDB 3.5
When creating more than 3 indexes the application just dies, getting a
Unable to connect to the remote server Status Code: ConnectFailure
The index creation code is farely straight forward:
private static void CreateIndexes(IDocumentStore documentStore)
{
new PurchaseOrder_QueryByExternalReference().Execute(documentStore);
new SupplierDocument_QueryBySupplierName().Execute(documentStore);
new ProductDocument_QueryByProductIdAndName().Execute(documentStore);
new PurchaseOrderLine_QueryableIndex().Execute(documentStore);
new PurchaseOrderLine_ForPurchaseOrderIndex().Execute(documentStore);
}
But the same happens if the
IndexCreation.CreateIndexes(typeof(MyIndexClass).Assembly, store);
method is called. This happens with any 3 indexes from the list on any order.
Full stack-trace is this:
exception
{"A task was canceled."}
Data: {System.Collections.ListDictionaryInternal}
Etag: null
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "A task was canceled."
Response: {StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: , Headers:
{
}}
ResponseString: "Unable to connect to the remote server Status Code: ConnectFailure"
Source: "Raven.Client.Lightweight"
StackTrace: " at Raven.Client.Connection.Implementation.HttpJsonRequest.<>c__DisplayClass36_0.<b__0>d.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\Implementation\HttpJsonRequest.cs:line 258
--- 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 Raven.Client.Connection.Implementation.HttpJsonRequest.d__381.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 312
--- 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 Raven.Client.Connection.Implementation.HttpJsonRequest.<ReadResponseJsonAsync>d__35.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Implementation\\HttpJsonRequest.cs:line 221
--- 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 Raven.Client.Connection.Async.AsyncServerClient.<>c__DisplayClass69_0.<<GetIndexAsync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\Async\\AsyncServerClient.cs:line 726
--- 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 Raven.Client.Connection.ReplicationInformerBase1.d__341.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 417
--- 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 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Raven.Client.Connection.ReplicationInformerBase1.d__331.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Client.Lightweight\\Connection\\ReplicationInformerBase.cs:line 316
--- 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 Raven.Client.Connection.Async.AsyncServerClient.<ExecuteWithReplication>d__1641.MoveNext() in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\Async\AsyncServerClient.cs:line 0
--- 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 Raven.Abstractions.Util.AsyncHelpers.<>c__DisplayClass1_11.<<RunSync>b__0>d.MoveNext() in C:\\Builds\\RavenDB-Stable-3.5\\Raven.Abstractions\\Util\\AsyncHelpers.cs:line 75
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Abstractions.Util.AsyncHelpers.RunSync[T](Func1 task) in C:\Builds\RavenDB-Stable-3.5\Raven.Abstractions\Util\AsyncHelpers.cs:line 89
at Raven.Client.Connection.ServerClient.GetIndex(String name) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Connection\ServerClient.cs:line 222\
at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Indexes\AbstractIndexCreationTask.cs:line 304
at Raven.Client.DocumentStoreBase.ExecuteIndex(AbstractIndexCreationTask indexCreationTask) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\DocumentStoreBase.cs:line 102
at Raven.Client.Indexes.AbstractIndexCreationTask.Execute(IDocumentStore store) in C:\Builds\RavenDB-Stable-3.5\Raven.Client.Lightweight\Indexes\AbstractIndexCreationTask.cs:line 221
at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.CreateIndexes(IDocumentStore documentStore) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 50
at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.ConfigureDocumentStore(IDocumentStore documentStore) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 38
at Persistence.Database.Adapter.RavenDb.RavenDbDocumentStoreFactory.Create(String ravenDbLocation, String ravenDbDatabase) in \my\route\Persistence.Database.Adapter\RavenDb\RavenDbDocumentStoreFactory.cs:line 22
at Persistence.Database.Adapter.PersistenceAdapter.<.ctor>b__8_0() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 53
at Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenDbUtilities() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 175
at Persistence.Database.Adapter.PersistenceAdapter.RegisterRavenLogic() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 86
at Persistence.Database.Adapter.PersistenceAdapter.Initialize() in \my\route\Persistence.Database.Adapter\PersistenceAdapter.cs:line 74
at My-Program.ConfigurePersistentAdapter(Settings settings) in \my\route\MessageQueueListener\MessageQueueListenerService.cs:line 153
at My-Program.AddBootstrapperExtension() in \my\route\net-stock-purchasing-service.MessageQueueListener\MessageQueueListenerService.cs:line 118
at My-Program.Startup() in \my\route\net-stock-purchasing-service.MessageQueueListener\MessageQueueListenerService.cs:line 78"
StatusCode: ServiceUnavailable
TargetSite: {Void MoveNext()}
When RavenDB 3.5 was release, something broke in the client package.
If you are running RavenDB.Client from 3.0.30000 to 3.0.30179, then it should work.
If you are running a higher version, then you will encounter (in certain conditions) this exception. To resolve that, you can use an alternate API: store.DatabaseCommands.PutIndexes.
var indexes = new List<AbstractIndexCreationTask>();
indexes.Add(new MyIndex1());
indexes.Add(new MyIndex2());
indexes.Add(new MyIndex....());
var transfos = new List<AbstractTransformerCreationTask>();
transfos.Add(new MyTransformer1());
transfos.Add(new MyTransformer2());
transfos.Add(new MyTransformer...());
// put indexes in 1 command
var indexesToPut = IndexCreation.CreateIndexesToAdd(indexes, documentStore.Conventions);
documentStore.DatabaseCommands.PutIndexes(indexesToPut);
// don't forget transformers
foreach (var item in transfos)
{
item.Execute(Store);
}
This should solve your problem.
I was encountering this problem after upgrading my client package. Note that the exception occurred only in console applications and not in my web applications.
That solved the issue for me:
var indexes = IndexCreation.CreateIndexesToAdd(new List<AbstractIndexCreationTask> {...}, store.Conventions);
var alreadyExisting = store.DatabaseCommands.GetIndexes(0, 128)
.ToDictionary(i => i.Name);
foreach (var index in indexes.Where(i => !alreadyExisting.ContainsKey(i.Name)))
store.DatabaseCommands.PutIndex(index.Name, index.Definition);
store.DatabaseCommands.PutIndexes(indexes);
In my case it turned out to be due to a mismatch of ravendb client library and the installed server. My application was running the latest version of the RavenDB client and the server is using version 3.0

SignalR + Redis backplane = System.InvalidOperationException: The queue is full

I use SignalR with redis backplane. To set up it, I use simple code
var redisConfig = new RedisScaleoutConfiguration("connectionString","eventKey");
GlobalHost.DependencyResolver.UseRedis(redisConfig);
Everything worked fine,but than I began to get following exceptions.
Unhandled exception in Portal UI:System.InvalidOperationException: The queue is full. at Microsoft.AspNet.SignalR.Messaging.ScaleoutStream.Send(Func2 send, Object state) at Microsoft.AspNet.SignalR.Infrastructure.Connection.Send(ConnectionMessage message) at Microsoft.AspNet.SignalR.Transports.TransportConnectionExtensions.SendCommand(ITransportConnection connection, String connectionId, CommandType commandType) at Microsoft.AspNet.SignalR.Transports.ForeverTransport.ProcessRequestCore(ITransportConnection connection) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequestPostGroupRead(HostContext context, String groupsToken) at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2,T3,TResult](Func4 func, T1 arg1, T2 arg2, T3 arg3) --- 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.Owin.Mapping.MapMiddleware.d__0.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.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.d__5.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.Owin.Security.Infrastructure.AuthenticationMiddleware1.<Invoke>d__0.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.Owin.Security.Infrastructure.AuthenticationMiddleware1.d__0.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.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.d__5.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.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I looked into redis cache . It seems that it's ok. It has enough space.
What doest 'The queue is full' mean? What is this queue? How can I avoid such exceptions?

Categories