danzuep / MailKitSimplified

Send and receive emails easily, fluently, with one line of code for each operation.
MIT License
79 stars 10 forks source link

.net Core MVC Dependency Injection Issue #33

Closed faisalbwn closed 1 year ago

faisalbwn commented 1 year ago

Dear Daniel,

I am facing following error when i am added dependency injection in my .net Core MVC appliation:

ObjectDisposedException: Cannot access a disposed object. Object name: 'LoggerFactory'.

Microsoft.Extensions.Logging.LoggerFactory.CreateLogger(string categoryName)
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>..ctor(IOptionsMonitor<TOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler..ctor(IOptionsMonitor<OpenIdConnectOptions> options, ILoggerFactory logger, HtmlEncoder htmlEncoder, UrlEncoder encoder, ISystemClock clock)
InvokeStub_OpenIdConnectHandler..ctor(object , object , IntPtr* )
System.Reflection.ConstructorInvoker.Invoke(object obj, IntPtr* args, BindingFlags invokeAttr)
System.Reflection.RuntimeConstructorInfo.InvokeWithManyArguments(RuntimeConstructorInfo ci, int argCount, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSite(ServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, string authenticationScheme)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
danzuep commented 1 year ago

Duplicate of https://github.com/danzuep/MailKitSimplified/issues/31

faisalbwn commented 1 year ago

I went through the Microsoft blog. But I am not disposing any dependency by myself in code. I am just adding SimplifiedMailKit dependency and than resolving it in my service. Once i do it, it start throwing this exception.

danzuep commented 1 year ago

I should have fixed it in #31 , try it out.