Closed iyhammad closed 8 years ago
Hi,
Can you share your DbContext hierarchy? I'm working on this issue to understand it.
I suppose this will solve your problem: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1119
I'm closing this issue. It will be released as v0.9.4. If it can not solve the problem, please re-open this issue. Thanks.
Hi, I've upgraded to ABP v0.9.4 and marked my MainDbContext as DefaultDbContext and this doesn't resolve my issue. In My System I've MainDbContext that inherits AbpZeroDbContext<Tenant, Role, User> and every module DbContext inherits MainDbContext. Also MainDbContext and every Module DbContext has AutoRepositoryTypes Thanks,
OK. We will solve the problem. But I need your help. First, can you share the stack trace and the exception message again. I improved the exception message, so we can see this "multiple dbcontext" list.
Is your MainDbContext abstract? DefaultDbContext attribute should be added to a non-abstract class. Try to add it to one of your modules (the most major/common module if one exists).
Hi Halil,
Thank you for your efforts towards resolving this issue.
You can find here a sample solution that demonstrate the issue https://github.com/iyhammad/AdventureWorks
to regenerate the issue Just do login using Postman.
My Stack Trace:
ERROR 2016-06-19 13:19:14,966 [7 ] eWorks.Web.Controllers.AccountController - Found more than one concrete type for given DbContext Type (AdventureWorks.EntityFramework.AdventureWorksDbContext) define MultiTenancySideAttribute with Tenant. Found types: AdventureWorks.EntityFramework.AdventureWorksDbContext, AdventureWorks.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, AdventureWorks.Sales.EntityFramework.EntityFramework.SalesDbContext, AdventureWorks.Sales.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
Abp.AbpException: Found more than one concrete type for given DbContext Type (AdventureWorks.EntityFramework.AdventureWorksDbContext) define MultiTenancySideAttribute with Tenant. Found types: AdventureWorks.EntityFramework.AdventureWorksDbContext, AdventureWorks.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, AdventureWorks.Sales.EntityFramework.EntityFramework.SalesDbContext, AdventureWorks.Sales.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
at Abp.EntityFramework.DbContextTypeMatcher`1.GetDefaultDbContextType(List`1 dbContextTypes, Type sourceDbContextType, MultiTenancySides tenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework.Common\DbContextTypeMatcher.cs:line 131
at Abp.EntityFramework.DbContextTypeMatcher`1.GetConcreteType(Type sourceDbContextType) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework.Common\DbContextTypeMatcher.cs:line 79
at Abp.EntityFramework.Uow.EfUnitOfWork.GetOrCreateDbContext[TDbContext](Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 140
at Abp.EntityFramework.Uow.UnitOfWorkExtensions.GetDbContext[TDbContext](IActiveUnitOfWork unitOfWork, Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkExtensions.cs:line 38
at Abp.EntityFramework.Uow.UnitOfWorkDbContextProvider`1.GetDbContext(Nullable`1 multiTenancySide) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\UnitOfWorkDbContextProvider.cs:line 38
at Abp.EntityFramework.Repositories.EfRepositoryBase`3.get_Context() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 25
at Abp.EntityFramework.Repositories.EfRepositoryBase`3.get_Table() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 30
at Abp.EntityFramework.Repositories.EfRepositoryBase`3.InsertAsync(TEntity entity) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Repositories\EfRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 80
at Castle.Proxies.Invocations.IRepository`2_InsertAsync_14.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 62
at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 41
at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 62
at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 41
at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 35
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IRepository`2Proxy_11.InsertAsync(AuditLog entity)
at Abp.Auditing.AuditingStore.SaveAsync(AuditInfo auditInfo) in D:\Halil\GitHub\module-zero\src\Abp.Zero\Auditing\AuditingStore.cs:line 24
at Abp.Auditing.AuditingStoreExtensions.<>c__DisplayClass0_0.<Save>b__0() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Auditing\AuditingStoreExtensions.cs:line 17
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- 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 Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
at Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t)
at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- 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 Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
at Nito.AsyncEx.AsyncContext.Run(Func`1 action)
at Abp.Threading.AsyncHelper.RunSync(Func`1 action) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\AsyncHelper.cs:line 42
at Abp.Auditing.AuditingStoreExtensions.Save(IAuditingStore auditingStore, AuditInfo auditInfo) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Auditing\AuditingStoreExtensions.cs:line 17
at Abp.Web.Mvc.Controllers.AbpController.HandleAuditingAfterAction(ActionExecutedContext filterContext) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.Web.Mvc\Web\Mvc\Controllers\AbpController.cs:line 466
at Castle.Proxies.AccountControllerProxy.OnActionExecuted_callback(ActionExecutedContext filterContext)
at Castle.Proxies.Invocations.AbpController_OnActionExecuted.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 29
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.AccountControllerProxy.OnActionExecuted(ActionExecutedContext filterContext)
at System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
My MainDbContext is not abstract. I tried to add the DefaultDbContext to any of the modules it didn't help. However by design the Default should be the Main for me I guess.
Thanks,
Thank you for sharing the code. I'm checking it.
Can you try this:
public class MyDbContextTypeMatcher : DbContextTypeMatcher
{
public MyDbContextTypeMatcher(ICurrentUnitOfWorkProvider currentUnitOfWorkProvider)
: base(currentUnitOfWorkProvider)
{
}
public override Type GetConcreteType(Type sourceDbContextType)
{
if (!sourceDbContextType.IsAbstract)
{
return sourceDbContextType;
}
return base.GetConcreteType(sourceDbContextType);
}
}
In PreInitialize method of your module, replace the service with your custom one:
Configuration.ReplaceService<IDbContextTypeMatcher, MyDbContextTypeMatcher>();
And see if this fixes the problem.
Note: You can write these code in your Web project or in any of your EF projects.
Thanks.
Thank you Halil, It resolved the issue. Is it a temporary solution?
No, this is the correct solution and will be included in the next release (so, you can remove your that code in the next release). Thank you for your support to test it.
You Welcome. I really enjoy working with ABP on daily basis.
OK, released v0.9.5. Just upgrade nuget packages and remove your custom code. Have a nice day.
Hi,
Background
I've a multi module system and every module has itsown DbContext. All the modules' DbContext inherits the base module DbContext which in turns inherits the AboZeroDbContext.
The Issue
After upgrading to Abp 0.9.3 I got the below exception everywhere in the system.
Stack trace:
Any thoughts ?