The service on Local Computer started then stopped - c#

I've created a Service that I've installed on several machines. They all work fine except for one. When I try to start the service via Windows Services I get the following error:
The My.Service service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
I've seen other posts suggesting you change the service's log on properties to log on as a local system account - I'm already doing this.
Event viewer gives me this information:
Application: myProject.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AggregateException
Stack:
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[[Microsoft.AspNetCore.Hosting.Internal.HostingApplication+Context, Microsoft.AspNetCore.Hosting, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](Microsoft.AspNetCore.Hosting.Server.IHttpApplication`1<Context>)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(Microsoft.AspNetCore.Hosting.IWebHost, System.Threading.CancellationToken, System.String)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(Microsoft.AspNetCore.Hosting.IWebHost)
at Nexus.Startup.Main(System.String[])
I've tried running the service manually from a command prompt and passing in --debug and received this error message:
09:05:47.289 [1] ERROR -
System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<DisposeAsync>d__13.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.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<DisposeAsync>d__20.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, TimeSpan timeout)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.DisposeListeners(List`1 listeners)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at MyProject.Startup.Main(String[] args) in D:\bamboo-home\xml-data\build-dir\163841\CUT-CUP-CR\repos\myProject\Startup.cs:line 42
---> (Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<DisposeAsync>d__13.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.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<DisposeAsync>d__20.MoveNext()<---
I'm fairly confused since this service starts up perfectly fine on other machines.
Here is my Startup.cs main method:
public static void Main(string[] args)
{
var exePath = Process.GetCurrentProcess().MainModule.FileName;
var directoryPath = Path.GetDirectoryName(exePath);
if (Debugger.IsAttached || args.Contains("--debug"))
{
var host = new WebHostBuilder()
.CaptureStartupErrors(true)
.UseKestrel()
.UseUrls("http://localhost:5000")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
else
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://localhost:5000")
.UseContentRoot(directoryPath)
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.RunAsService();
}
}

#ScottChamberlain Yes, I passed in --debug – Roka545
You can't do that. Run() is a blocking call that does not allow the windows service to fully start. You need to always need to do RunAsSevice() from inside a service even if you are debugging. The pattern I normally do is
if (args.Contains("--console"))
{
var host = new WebHostBuilder()
.CaptureStartupErrors(true)
.UseKestrel()
.UseUrls("http://localhost:5000")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
else
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://localhost:5000")
.UseContentRoot(directoryPath)
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.RunAsService();
}
So debugger attached or not, the service runs as a service when you start it from within a service. If you want to run it standalone (like in F5 from visual studio) you pass --console to the arguments.

Related

Failing Container orchestration on the Microsoft Service Fabric

i tried to containerize a simple Service Fabric Project into a Service Fabric Container Project.
I used the Create your first Service Fabric container application on Windows manual (https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/service-fabric/service-fabric-get-started-containers.md).
So at the first step i defined my docker image from VotingData service. I just made an own solution out of the service and just added the dockerfile and built it.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
ADD . .
RUN dotnet publish \
-c Release \
-o ./output
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/output .
EXPOSE 8000
ENTRYPOINT VotingData.exe
Then i pushed it into my azure image registry, and added it into my Service Fabric application as a container service, like the steps in the manual.
After Starting the SF cluster the Application and nodes are starting in the SF explorer after a while. The Problem is, the local VotingData container is just running for a view seconds.
When i debug into the error exited container i get this log:
$ docker logs sf-4-1a5af364-f71e-4d06-b713-76a6150f92db_d9bda8c5-561c-47c1-88f3-15391d3d2ae3
[17:34:34 INF] Start register Service
Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Fabric.Common.AppTrace' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'FabricCommon.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
at System.Fabric.Interop.NativeCommon.FabricGetConfigStore(Guid& riid, IFabricConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.NativeConfigStore.CreateHelper(IFabricConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.NativeConfigStore.<>c__DisplayClass3_0.<FabricGetConfigStore>b__0()
at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func`1 func, String functionTag, String functionArgs)
at System.Fabric.Interop.Utility.<>c__DisplayClass27_0`1.<WrapNativeSyncInvokeInMTA>b__0()
at System.Fabric.Interop.Utility.RunInMTA[TResult](Func`1 func)
at System.Fabric.Interop.Utility.WrapNativeSyncInvokeInMTA[TResult](Func`1 func, String functionTag)
at System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(IConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.Tracing.TraceConfig.InitializeFromConfigStore(Boolean forceUpdate)
at System.Fabric.Common.AppTrace..cctor()
--- End of inner exception stack trace ---
at System.Fabric.Common.AppTrace.get_TraceSource()
at System.Fabric.Interop.AsyncCallOutAdapter2`1.Start(CancellationToken cancellationToken)
at System.Fabric.Interop.AsyncCallOutAdapter2`1.WrapNativeAsyncInvoke(String functionTag, Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, Boolean runContinuationsAsynchronously)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvoke[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, Boolean runContinuationsAsynchronously, String functionTag)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvoke[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, String functionTag)
at System.Fabric.Interop.Utility.<>c__DisplayClass20_0`1.<WrapNativeAsyncInvokeInMTA>b__0()
at System.Fabric.Interop.Utility.RunInMTA[TResult](Func`1 func)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvokeInMTA[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, String functionTag)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvokeInMTA[TResult](Func`2 beginFunc, Func`2 endFunc, CancellationToken cancellationToken, String functionTag)
at System.Fabric.FabricRuntime.NativeFabricRuntimeFactory.GetNodeContextAsync(TimeSpan timeout, CancellationToken cancellationToken)
at System.Fabric.FabricRuntime.GetNodeContextAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.RuntimeContext.GetOrCreateAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.ServiceRuntime.RegisterServiceAsync(String serviceTypeName, Func`2 serviceFactory, TimeSpan timeout, CancellationToken cancellationToken)
at VotingData.Program.Main() in C:\app\Program.cs:line 37
So in my eyes the problem is, that the SF cannot register the containerized service in the program.cs in the main method when it calls registerServiceAsync(). But the image is missing the dependency to the SF or something else.
private static void Main()
{
try
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Information()
.WriteTo.File(#"c:\temp\VotingDataLog.txt",
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
.CreateLogger();
// The ServiceManifest.XML file defines one or more service type names.
// Registering a service maps a service type name to a .NET type.
// When Service Fabric creates an instance of this service type,
// an instance of the class is created in this host process.
Log.ForContext<VotingData>().Information("Start register Service");
ServiceRuntime.RegisterServiceAsync("VotingDataType",
context => new VotingData(context)).GetAwaiter().GetResult();
Log.ForContext<VotingData>().Information("Service registered");
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(VotingData).Name);
// Prevents this host process from terminating so services keep running.
Thread.Sleep(Timeout.Infinite);
}
catch (Exception e)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
throw;
}
I also tried another option, so i added an image with the SF runntime.
I used the edalx/servicefabric-runtime:dotnetcore-3.1.2 image from https://github.com/edalx/servicefabric-runtime
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
ADD . .
RUN dotnet publish \
-c Release \
-o ./output
FROM edalx/servicefabric-runtime:dotnetcore-3.1.2
WORKDIR /app
COPY --from=build-env /app/output .
EXPOSE 8000
ENTRYPOINT VotingData.exe
Then i got this error
$ docker logs sf-3-ed4968b2-0783-4550-9e26-8fe2c4879851_dcdc6636-359d-40ca-b499-e0e3ad805dca
[16:44:51 INF] Start register Service
Unhandled exception. System.Fabric.FabricException: An error occurred during this operation. Please check the trace logs for more details.
---> System.Runtime.InteropServices.COMException (0x80071CC0): 0x80071CC0
at System.Fabric.Interop.NativeRuntime.FabricEndGetNodeContext(IFabricAsyncOperationContext context)
at System.Fabric.FabricRuntime.NativeFabricRuntimeFactory.GetNodeContextEndWrapper(IFabricAsyncOperationContext context)
at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)
--- End of inner exception stack trace ---
at Microsoft.ServiceFabric.Services.Runtime.RuntimeContext.GetOrCreateAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.ServiceRuntime.RegisterServiceAsync(String serviceTypeName, Func`2 serviceFactory, TimeSpan timeout, CancellationToken cancellationToken)
at VotingData.Program.Main() in C:\app\Program.cs:line 37
So the dependency was there but the main method errored when it called registerServiceAsync().

HttpControllerContext.Configuration is sometimes null during Content negotiation

We are setting up a ASP.NET 4.6.2 Web Api host and noticing that some requests fail because of the following error:
HttpControllerContext.Configuration must not be null.
I've been unable to reproduce the issue and wanted to ask if anybody could steer me in the right direction?
This is the stack trace:
[0] System.InvalidOperationException "HttpControllerContext.Configuration must not be null."
at System.Web.Http.Results.NegotiatedContentResult`1.ApiControllerDependencyProvider.EnsureResolved()
at System.Web.Http.Results.NegotiatedContentResult`1.ApiControllerDependencyProvider.get_ContentNegotiator()
at System.Web.Http.Results.BadRequestErrorMessageResult.Execute()
at System.Web.Http.Results.BadRequestErrorMessageResult.ExecuteAsync(CancellationToken cancellationToken)
at System.Web.Http.Controllers.ApiControllerActionInvoker.d__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.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()
A similar error occurred in my tests when adding headers to a BadRequestErrorMessageResult. The fix only required to initialize the controller's Configuration.
...and subsequently initialize the Request.
So my test's setup ended up looking something like
public class FooControllerTest
{
private FooController _sut;
[Setup]
public void Setup()
{
_sut = new FooController();
_sut.Configuration = new System.Web.Http.HttpConfiguration();
_sut.Request = new System.Net.Http.HttpRequestMessage();
}
}
Hope that helps.

ReflectionTypeLoadException exception in Asp.Net Core in-memory TestServer

I create a IWebHostBuilder like so:
public IWebHostBuilder GetWebHostBuilder()
{
return new WebHostBuilder().UseContentRoot(_contentRoot)
.ConfigureServices(InitializeServiceCollection)
.UseEnvironment(_environment)
.UseConfiguration(GetConfiguration())
.UseStartup(typeof(TStartup));
}
Here, the InitializeServiceCollection is implemented like so:
private void InitializeServiceCollection(IServiceCollection services)
{
var manager = new ApplicationPartManager();
manager.ApplicationParts.Add(new AssemblyPart(_assembly));
manager.FeatureProviders.Add(new ControllerFeatureProvider());
manager.FeatureProviders.Add(new ViewComponentFeatureProvider());
services.AddSingleton(manager);
}
Then I create the TestServer like so:
var myTestServer = new TestServer(GetWebHostBuilder());
Here I get the exception (full exception below). It gets thrown at services.AddAutoMapper(); method call in the system under test. However, when I run the system under test on it's own and test it manually with Postman, it's working fine and the object mapping with Automapper is working well too. It just raises the exception in the integration test.
Full exception:
System.AggregateException : One or more errors occurred. (Unable to load one or more of the requested types.
Could not load type 'Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalFullAnnotationNames' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=2.2.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.) (The following constructor parameters did not have matching fixture data: TestFixture fixture)
---- System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types.
Could not load type 'Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalFullAnnotationNames' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=2.2.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
---- The following constructor parameters did not have matching fixture data: TestFixture fixture
----- Inner Stack Trace #1 (System.Reflection.ReflectionTypeLoadException) -----
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at AutoMapper.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection services, Action`2 configAction, IEnumerable`1 assembliesToScan) in xxx\automapper-extensions-microsoft-dependencyinjectio\src\AutoMapper.Extensions.Microsoft.DependencyInjection\ServiceCollectionExtensions.cs:line 72
at xxx.Startup.ConfigureServices(IServiceCollection services) in xxx\Startup.cs:line 35
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
at xxx.Tests.TestFixture.InitializeServer() in xxx.Tests\TestFixture.cs:line 67
at xxx.Tests.TestFixture..ctor() in xxx.Tests\TestFixture.cs:line 31
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----
So, I managed to resolve the issue by replacing services.AddAutoMapper() with services.AddAutoMapper(Type[] types) overload. Not sure what is wrong with the original method, but in order to avoid that reflective call on the assemblies, I used this overload and it's working now.

Unable to integrate OpenXML (documentformat.openxml.*) in C# bot framework, getting the error " Autofac.Core.DependencyResolutionException "

In order to refine a powerpoint(.pptx) file, I have used OpenXML SDK(DocumentFormat.OpenXML) which works fine as a console Application.
However, as the requirement was to implement the same in bot framework, I have added the required nuget package, viz., 'DocumentFormat.OpenXml.*'. The call to a new
Dialog in the messageController throws an error at this line:
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
Bot works fine in emulator until I add the nuget package 'DocumentFormat.OpenXml.*'. However, it throws the mentioned error. Could not find relevant articles.
complete Method Code:
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
try
{
if (activity.GetActivityType() == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
}
catch (Exception ex)
{
activity.CreateReply(ex.Message);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
Exception:
An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IPostToBot (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = QueueDrainingDialogTask (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask (Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = AlwaysSendDirect_BotToUser (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser (Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser), Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)
Inner Exception:
An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = QueueDrainingDialogTask (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask (Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = AlwaysSendDirect_BotToUser (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser (Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser), Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)
Stack Trace:
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters)
at Autofac.Core.Resolving.InstanceLookup.<Execute>b__5_0()
at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func1 creator)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
at Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.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 Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 108
--- 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 CredentialsAutomation.MessagesController.d__0.MoveNext() in C:\Users\Tanu\source\repos\CredentialsAutomation\CredentialsAutomation\Controllers\MessagesController.cs:line 27
For all those who have been working on a similar problem, the solution would be to proceed with following OpenXml nuget packages:
DocumentFormat.OpenXml;
DocumentFormat.OpenXml.Presentation;
DocumentFormat.OpenXml.Spreadsheet;

Service Fabric ASP.NET core website stops working after running for multiple days

I have an Azure Service Fabric cluster. With a statefull service and stateless service.
The stateless service is an public facing asp.net core website. With multiple SQL connection strings and a connection to Azure Storage account.
When it runs for a longer time (multiple days), sometimes It hangs and I'm unable to identify the problem.
When I restart (from the SF cluster dashboard) the node running the service. It starts working again.
In the logs of the ASP.NET core application this was the last log. I don't know what
System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. at System.ArraySegment`1..ctor(T[] array, Int32 offset, Int32 count) at Microsoft.Net.Http.Server.RawUrlHelper.GetPath(Byte[] raw) at Microsoft.Net.Http.Server.RequestUriBuilder.DecodeAndUnescapePath(Byte[] rawUrlBytes) at Microsoft.Net.Http.Server.Request..ctor(RequestContext requestContext, NativeRequestContext nativeRequestContext) at Microsoft.Net.Http.Server.RequestContext..ctor(WebListener server, NativeRequestContext memoryBlob) at Microsoft.Net.Http.Server.AsyncAcceptContext.IOCompleted(AsyncAcceptContext asyncResult, UInt32 errorCode, UInt32 numBytes) --- 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.AspNetCore.Server.WebListener.MessagePump.d__22.MoveNext()
In the event viewer (Application, ServiceFabric Admin, Service Fabric Operational) of the node that was running the service was nothing out of the ordinary. This already happend multiple times.
Is there any place I can find more internal logging?
Or does anybody now where the error comes from?
My code to run asp.net core looks like this:
protected override IEnumerable CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new WebListenerCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
return new WebHostBuilder().UseWebListener()
.ConfigureServices(
services => services
.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup()
.UseApplicationInsights()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};

Categories