ObjectDisposedException in ASP.NET Boilerplate manage services - aspnetboilerplate

I've decided to separate logic from RoleAppService to RoleService, because I need to use role methods in other app services. By separating logic I can avoid injecting endpoints to other endpoints (e.g. RoleAppService to UserAppService) and possible circular dependency. API is also not visible outside - that's why class inherit from AbpServiceBase, no ApplicationService (which make service visible in swagger). Unfortunately, when I try to use boilerplate manager classes (e.g. RoleManager, UserManager) inside RoleService method, following exception is thrown:
Cannot access a disposed object.
Object name: 'RoleManagerProxy'.
With stack trace:
at Microsoft.AspNetCore.Identity.RoleManager`1.ThrowIfDisposed()
at Microsoft.AspNetCore.Identity.RoleManager`1.FindByNameAsync(String roleName)
at Castle.Proxies.Invocations.RoleManager`1_FindByNameAsync.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.RoleManagerProxy.FindByNameAsync(String roleName)
at Abp.Authorization.Roles.AbpRoleManager`2.<CheckDuplicateRoleNameAsync>d__48.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Authorization.Roles.AbpRoleManager`2.<UpdateAsync>d__42.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.ZeroCore\Authorization\Roles\AbpRoleManager.cs:line 283
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VZero.Roles.RoleService.<Create>d__6.MoveNext() in C:\Users\Marcin\source\repos\translink.vendorforum\Translink.Api\src\VZero.Application\Roles\RoleService.cs:line 42
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VZero.Roles.RoleService.<CreateOtherDocumentUserRole>d__9.MoveNext() in C:\Users\Marcin\source\repos\translink.vendorforum\Translink.Api\src\VZero.Application\Roles\RoleService.cs:line 94
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VZero.Roles.RoleService.<GetOtherDocumentRole>d__11.MoveNext() in C:\Users\Marcin\source\repos\translink.vendorforum\Translink.Api\src\VZero.Application\Roles\RoleService.cs:line 107
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VZero.Roles.RoleService.<UpdateOtherDocumentUserRole>d__10.MoveNext() in C:\Users\Marcin\source\repos\translink.vendorforum\Translink.Api\src\VZero.Application\Roles\RoleService.cs:line 100
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at VZero.Users.UserAppService.<Update>d__20.MoveNext() in C:\Users\Marcin\source\repos\translink.vendorforum\Translink.Api\src\VZero.Application\Users\UserAppService.cs:line 226
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at lambda_method(Closure , Object )
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.<Execute>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()
Error seems to be related with framework configuration. I've tried to end service name with AppService, but it didn't help at all. Service is registered in Windsor Castle framework. What interesting - inside class properly works boilerplate repositories, like RoleRepository, UserReposistory - unfortunately RoleManager/UserManager not. Below is the fragment of the the class:
public class RoleService : AbpServiceBase, IRoleService
{
private readonly RoleManager _roleManager;
private readonly IRepository<Role> _roleRepository;
private readonly UserManager _userManager;
private readonly IRepository<User, long> _userRepository;
private readonly IPermissionManager _permissionManager;
public RoleService(RoleManager roleManager, IRepository<Role> roleRepository,
UserManager userManager, IRepository<User, long> userRepository,
IPermissionManager permissionManager)
{
_roleManager = roleManager;
_roleRepository = roleRepository;
_userManager = userManager;
_userRepository = userRepository;
_permissionManager = permissionManager;
}
public async Task<RoleDto> Create(CreateRoleDto createRoleDto, Action<IdentityResult> checkErrorsMethod)
{
var role = ObjectMapper.Map<Role>(createRoleDto);
role.SetNormalizedName();
await _roleManager.UpdateAsync(role); // here exception is thrown
var grantedPermissions = _permissionManager
.GetAllPermissions()
.Where(p => createRoleDto.Permissions.Contains(p.Name))
.ToList();
await _roleManager.SetGrantedPermissionsAsync(role, grantedPermissions);
return role.MapTo<RoleDto>();
}
I would be so grateful for any help.

If you add [UnitOfWork] attribute, don't forget to make method public virtual

Related

Issue installing version 10 on a new DNN 9.2.2

I'm trying to install the blog app and keep getting an error message.
05/26/2019 20:49:27
Admin Alert
host
2sxc-Api Auto-Log Exception 2sInst[3e Path http://enjoythisworld.com/deskt
2sxc-Api:Auto-Log Exception
2sInst[3e]:Path: http://enjoythisworld.com/desktopmodules/2sxc/api/app-sys/installer/installpackage?packageUrl=https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip
2sInst[3e]DNN.Enviro[1b]Dnn.Publsh[70]:()
2sInst[3e]:install package:https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip
2sInst[3e]Dnn.MapA2I[53]:get appid from instance for Z:2 Mod:451 not found = null
2sInst[3e]Zip.Imp[6f]:import zip from url:https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip, isApp:True
2sInst[3e]Zip.Imp[6f]:try to download:https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip to:C:\Inetpub\vhosts\enjoythisworld.com\httpdocs\desktopmodules\tosic_sexycontent_\4po5clpp.vke.zip
Server Name: GenericAU04
Check
05/26/2019 20:49:27
General Exception
host
Enjoy This World
AbsoluteURL /desktopmodules/2sxc/api/app-sys/installer/installpackage Defa
AbsoluteURL:/desktopmodules/2sxc/api/app-sys/installer/installpackage
DefaultDataProvider:DotNetNuke.Data.SqlDataProvider, DotNetNuke
ExceptionGUID:f9b14e08-800d-4577-b7f3-4751cf4e96ec
AssemblyVersion:
PortalId:-1
UserId:-1
TabId:-1
RawUrl:
Referrer:
UserAgent:
ExceptionHash:EUTd+51qrnU8qi8gRlrnBDlmOGY=
Message:An error occurred while installing the app: Could not download app package from 'https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip'.
StackTrace:
at ToSic.SexyContent.WebApi.InstallerController.InstallPackage(String packageUrl) in C:\Projects\2sxc-dnn742\Website\DesktopModules\ToSIC_SexyContent\Sxc WebApi\InstallerController.cs:line 51 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, 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 System.Web.Http.Tracing.ITraceWriterExtensions.d__18`1.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.Web.Http.Controllers.ApiControllerActionInvoker.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 System.Web.Http.Tracing.ITraceWriterExtensions.d__18`1.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.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Web.Http.Filters.ActionFilterAttribute.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 System.Web.Http.Filters.ActionFilterAttribute.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 System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Web.Http.Filters.ActionFilterAttribute.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 System.Web.Http.Filters.ActionFilterAttribute.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 System.Web.Http.Controllers.ActionFilterResult.d__2.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.Web.Http.Filters.AuthorizationFilterAttribute.d__2.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.Web.Http.Filters.AuthorizationFilterAttribute.d__2.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.Web.Http.Filters.AuthorizationFilterAttribute.d__2.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.Web.Http.Filters.AuthorizationFilterAttribute.d__2.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.Web.Http.Controllers.ExceptionFilterResult.d__0.MoveNext()
InnerMessage:Could not download app package from 'https://2sxc.org/Portals/0/adam/AppCatalog/5EMutByRNEWtODu1sMkpDg/Download/2sxcApp_Blog_03.00.02.zip'.
InnerStackTrace:
at ToSic.Eav.Apps.ImportExport.ZipImport.ImportZipFromUrl(String packageUrl, Boolean isAppImport) at ToSic.SexyContent.WebApi.InstallerController.InstallPackage(String packageUrl) in C:\Projects\2sxc-dnn742\Website\DesktopModules\ToSIC_SexyContent\Sxc WebApi\InstallerController.cs:line 32
Source:ToSic.SexyContent.WebApi
FileName:
FileLineNumber:0
FileColumnNumber:0
Method:
Server Name: GenericAU04
I'm guessing that your server doesn't have an internet connection - maybe communication between the server and the internet is prohibited. To work around this, download the app directly from the app catalog and upload/install it from the zip.
Best, iJungleboy

Unable to connect to Amazon MQ using MassTransit

I am attempting to publish messages to an Amazon MQ instance using the latest version of the MassTransit.ActiveMQ package.
I found an example in the MassTransit source that appears to show a successful connection to Amazon MQ. I tried to replicate that example in my own application using my Amazon MQ instance:
public static void Main(string[] args)
{
Console.WriteLine("Creating connection to Amazon MQ...");
var busControl = Bus.Factory.CreateUsingActiveMq(cfg =>
{
cfg.Host("b-abcxyz-1.mq.us-east-1.amazonaws.com", 61617, h =>
{
h.Username("user");
h.Password("pass");
h.UseSsl();
});
});
busControl.StartAsync().Wait();
Console.WriteLine("Connected.");
Console.ReadKey();
busControl.StopAsync().Wait();
}
I receive the following error when attempting to start the bus. It seems to use the activemq scheme instead of ssl like I expected.
ActiveMQ Connect Failed: ReceiveTranport Faulted, Restartingactivemq://b-abcxyz-1.mq.us-east-1.amazonaws.com:61617/
Unhandled Exception: System.AggregateException: One or more errors occurred. (ReceiveTranport Faulted, Restartingactivemq://b-abcxyz-1.mq.us-east-1.amazonaws.com:61617/) ---> MassTransit.ActiveMqTransport.ActiveMqConnectException: ReceiveTranport Faulted, Restartingactivemq://b-72f33f22-0856-47ef-a5fb-e0ab19ab7aff-1.mq.us-east-1.amazonaws.com:61617/ ---> System.NotSupportedException: The requested security protocol is not supported.
at System.Net.SecurityProtocol.ThrowOnNotAllowed(SslProtocols protocols, Boolean allowNone)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at Apache.NMS.ActiveMQ.Transport.Tcp.SslTransport.CreateSocketStream()
at Apache.NMS.ActiveMQ.Transport.Tcp.TcpTransport.Start()
at Apache.NMS.ActiveMQ.Transport.TransportFilter.Start()
at Apache.NMS.ActiveMQ.Transport.TransportFilter.Start()
at Apache.NMS.ActiveMQ.Transport.WireFormatNegotiator.Start()
at Apache.NMS.ActiveMQ.Transport.TransportFilter.Start()
at Apache.NMS.ActiveMQ.Transport.TransportFilter.Start()
at Apache.NMS.ActiveMQ.Connection.CheckConnected()
at Apache.NMS.ActiveMQ.Connection.Start()
at MassTransit.ActiveMqTransport.Transport.ConnectionContextFactory.<CreateConnection>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.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.ActiveMqTransport.Transport.ConnectionContextFactory.<CreateSharedConnection>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.HandleNonSuccessAndDebuggerNotification(Task task)
at GreenPipes.Agents.PipeContextSupervisor`1.<GreenPipes-IPipeContextSource<TContext>-Send>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at GreenPipes.Agents.PipeContextSupervisor`1.<GreenPipes-IPipeContextSource<TContext>-Send>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at GreenPipes.Agents.PipeContextSupervisor`1.<GreenPipes-IPipeContextSource<TContext>-Send>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.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.ActiveMqTransport.Transport.ActiveMqReceiveTransport.<<Receiver>b__15_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MassTransit.ActiveMqTransport.Transport.ActiveMqReceiveTransport.<<Receiver>b__15_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.Policies.PipeRetryExtensions.<Retry>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MassTransit.Policies.PipeRetryExtensions.<Retry>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.ActiveMqTransport.Transport.ActiveMqReceiveTransport.<Receiver>d__15.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.ActiveMqTransport.Transport.ActiveMqHost.Handle.<ReadyOrNot>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.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.MassTransitBus.Handle.<ReadyOrNot>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.HandleNonSuccessAndDebuggerNotification(Task task)
at GreenPipes.Internals.Extensions.TaskExtensions.<UntilCompletedOrCanceled>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.MassTransitBus.<StartAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at MassTransit.MassTransitBus.<StartAsync>d__27.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at MassTransitActiveMQ.Program.Main(String[] args) in /home/ec2-user/MassTransitActiveMQ/MassTransitActiveMQ/Program.cs:line
I've resolved the issue, related to the SSL (requires TLS) protocol and will be committing the fix shortly. It will be available in version 5.0.2 soon.

EF Core: An exception occurred in the database while iterating the results of a query

I'm getting this error from my web app hosted in Azure. It runs ok for a few days and then suddenly stops working.
Is there an issue with the connection perhaps? Which object reference does not have an instance?
YYYY-MM-DD hh:mm:ss [Error] An exception occurred in the database while iterating the results of a query.
System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable.AsyncEnumerator.<BufferAllAsync>d__12.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.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.EntityFrameworkCore.Query.RelationalQueryContext.<RegisterValueBufferCursorAsync>d__14.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.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable.AsyncEnumerator.<BufferlessMoveNext>d__9.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable.AsyncEnumerator.<MoveNext>d__8.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.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.SelectAsyncEnumerable`2.SelectAsyncEnumerator.<MoveNext>d__4.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.<_FirstOrDefault>d__82`1.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.TaskResultAsyncEnumerable`1.Enumerator.<MoveNext>d__3.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.SelectAsyncEnumerable`2.SelectAsyncEnumerator.<MoveNext>d__4.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.<MoveNext>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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at MyProject.Data.SectionRepository.<GetByTypePathAndAlias>d__6.MoveNext() in /Users/webaccount/myproject/src/MyProject.Data/Repositories/SectionRepository.cs:line 34
There's nothing special about my repository or entity code.
public async Task<Section> GetByTypeId(string typeId)
{
var sections = from s in this.DbContext.Sections
where s.TypeId == typeId
select s;
return await sections.FirstOrDefaultAsync(); // <-- LINE 34
}
This is my entity.
public class Section
{
[Key]
public int Id { get; set; }
public DateTimeOffset CreatedDate { get; set; }
public string TypeId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
Is it related to this perhaps? https://github.com/aspnet/EntityFrameworkCore/issues/8026
Will it help if I convert my repository methods to sync and staying async at the Controller?
It runs ok for a few days and then suddenly stops working.
Object reference not set to an instance of an object
Firstly, you can try to remote debug your web app and check the this.DbContext.
Secondly, you can create/use a context instance per request, and this artciel shows some general guidelines when deciding on the lifetime of the context, you can check it.

Operation is not valid due to the current state of the object

An error has occurred.
Operation is not valid due to the current state of the object.
System.InvalidOperationException
at
Microsoft.Bot.Builder.Dialogs.Conversation.<>c__31.<ResumeAsync>b__3_0()
at
Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.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.Bot.Builder.Dialogs.Internals.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.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.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.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.Bot.Builder.Dialogs.Internals.SerializingDialogTask.d__41.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.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__21.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.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.d__21.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.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.d__51.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.Bot.Builder.Dialogs.Internals.LogPostToBot.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.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.Bot.Builder.Dialogs.Conversation.d__51.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.Bot.Builder.Dialogs.Conversation.<ResumeAsync>d__31.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.Runtime.CompilerServices.TaskAwaiter.GetResult() at
BotApplication.Controllers.OAuthCallbackController.d__0.MoveNext()
in
C:\BotApplication\BotApplication\Controllers\OAuthCallbackController.cs:line
55 --- 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.Threading.Tasks.TaskHelpersExtensions.d__3`1.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.Web.Http.Controllers.ApiControllerActionInvoker.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
System.Web.Http.Controllers.ActionFilterResult.d__2.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.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
This is happening when i'm trying to resume a conversation after user authentication.
I call authentication this way :
In my first dialog :
var message = context.MakeMessage();
await context.Forward(new SecondDialog(), HandleOptions, message, CancellationToken.None);
Then in my SecondDialog have this :
var message = await argument;
MyStaticModel.toId = message.From.Id;
MyStaticModel.toName = message.From.Name;
MyStaticModel.fromId = message.Recipient.Id;
MyStaticModel.fromName = message.Recipient.Name;
MyStaticModel.serviceUrl = message.ServiceUrl;
MyStaticModel.channelId = message.ChannelId;
MyStaticModel.conversationId = message.Conversation.Id;
await context.Forward(new SimpleFacebookAuthDialog(message), ResumeAfterLogIn, message, CancellationToken.None);
In my Facebook Dialog i make resumption cookie this way :
public SimpleFacebookAuthDialog(IMessageActivity msg)
{
ResumptionCookie = new ResumptionCookie(msg);
}
And when user authenticate i handle authentication :
public async Task<HttpResponseMessage> OAuthCallback([FromUri] string userId, [FromUri] string botId, [FromUri] string conversationId, [FromUri] string channelId, [FromUri] string serviceUrl, [FromUri] string locale, [FromUri] string code, [FromUri] string state, CancellationToken token)
{
//Get the resumption cookie
Address address = new Address
(
// purposefully using named arguments because these all have the same type
botId: FacebookHelpers.TokenDecoder(botId),
channelId: channelId,
userId: FacebookHelpers.TokenDecoder(userId),
conversationId: FacebookHelpers.TokenDecoder(conversationId),
serviceUrl: FacebookHelpers.TokenDecoder(serviceUrl)
);
//var resumptionCookie = new ResumptionCookie(FacebookHelpers.TokenDecoder(userId), FacebookHelpers.TokenDecoder(botId), FacebookHelpers.TokenDecoder(conversationId), channelId, FacebookHelpers.TokenDecoder(serviceUrl), locale: locale);
var resumptionCookie = new ResumptionCookie(address, userName: null, isGroup: false, locale: locale);
// Exchange the Facebook Auth code with Access token
var accessToken = await FacebookHelpers.ExchangeCodeForAccessToken(resumptionCookie, code, SimpleFacebookAuthDialog.FacebookOauthCallback.ToString());
// Create the message that is send to conversation to resume the login flow
var msg = resumptionCookie.GetMessage();
msg.Text = $"token:{accessToken.AccessToken}";
// Resume the conversation to SimpleFacebookAuthDialog
await Conversation.ResumeAsync(resumptionCookie, msg, CancellationToken.None);
It falls on the last line of code. When Resuming conversation.
Any help ?
I got the same error when I run tests in vs 2019.
I could solve this by cleaning the solution ,closing vs and deleting temp files anf re launching vs-2019.
I followed the link https://developercommunity.visualstudio.com/content/problem/875545/xunit-test-net-core-project-with-vs-2019-is-throwi.html
I fix this guys.
I don't know what the real reason is, but when i used to await for argument and store it as a message, later, parameters were wrong in resumption cookie.
Now, i cast argument as activity :
var message = (Activity)context.Activity;
And it works properly.
Problem solved :)
I got this error message when attempting to display adaptive cards. It turned out I had added the json files to the solution as content and not as embedded resources. After switching them to be embedded resources they displayed fine.

Web API CORS OPTION returns 500 randomly only on azure

Im developing a .NET Web Api (using OWIN) and a ember app consuming the web api. The web api is hosted on azure (api app). The problem is that sometimes the option call is failing (500 error) and the gui hangs. If I triggers the option call again it works again. If Im running the api on my local IIS, this problem never happens. The problem occurs most often when I have not done anything/triggered any ajax calls in the web app for awhile (5 min). Any clue why this is happening?
This is my startup config:
public partial class
Startup
{
public void Configuration(IAppBuilder app)
{
//enable cors
app.UseCors(CorsOptions.AllowAll);
//enable hangfire
Hangfire.GlobalConfiguration.Configuration
.UseSqlServerStorage("DbConnection")
.UseActivator(new StructureMapJobActivator(IoC.Initialize()));
app.UseHangfireDashboard();
app.UseHangfireServer();
//automapper
AutoMapperBootstrapper.Bootstrap();
//oauth 2
var userManager = new UserManager();
var authConfig = new SentinelAuthorizationServerOptions()
{
UserManager = userManager,
ClientManager = new ClientManager(),
};
var shaProvider = new SHA2CryptoProvider();
var onBoardTokenRepository = new OnBoardTokenRepository(new ConnectionFactory(new Configuration()), "DbConnection");
authConfig.TokenManager = new TokenManager(LogManager.GetLogger<Startup>(), userManager, new PrincipalProvider(shaProvider), shaProvider, new TokenFactory(), onBoardTokenRepository);
app.UseSentinelAuthorizationServer(authConfig);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
I found this error in the azure event log:
https://microsoft-apiapp08044e6364624e2e88cfda954ace012a.azurewebsites.net:443/job/getemployerjobs/job/getemployerjobs104.45.82.120FalseIIS APPPOOL\Microsoft-ApiApp08044e6364624e2e88cfda954ace012a108IIS APPPOOL\Microsoft-ApiApp08044e6364624e2e88cfda954ace012aFalse at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace)
at System.Web.HttpHeaderCollection.Set(String name, String value)
at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key, String[] values)
at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(String key, String[] value)
at Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
at Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
at Microsoft.Owin.HeaderDictionary.AppendValues(String key, String[] values)
at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.<.ctor>b__2(OAuthChallengeContext context)
at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.ApplyChallenge(OAuthChallengeContext context)
at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.ApplyResponseChallengeAsync()
at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseCoreAsync>d__b.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.AuthenticationHandler.<ApplyResponseAsync>d__8.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.AuthenticationHandler.<TeardownAsync>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.AuthenticationMiddleware`1.<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.AuthenticationMiddleware`1.<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.Mapping.MapMiddleware.<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.Cors.CorsMiddleware.<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.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>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.<DoFinalWork>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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
It seems this is related to Microsofts OWIN implementation: http://katanaproject.codeplex.com/discussions/540202 .
The relevant pull request is here: https://katanaproject.codeplex.com/workitem/263
The underlying OWIN OAuth middleware sometimes "seals off" the response when it creates a response.

Resources