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().
Related
I am using a MongoDB 3.4.4 instance from official docker image in my staging environment machine. I use MongoDB.Driver NuGet package 2.5.0 for connect from code.
It's works fine when I connect from deployed application (running in docker container from aspnetcore:2.0.3 base image). I have a some set of integration tests for my application. In application project and tests project connection with Mongo creation is same and as see below:
services.AddSingleton<IMongoClient>(s =>
{
var config = s.GetService<ISettings>();
var logger = s.GetService<ILogger<IMongoClient>>();
var settings = MongoClientSettings.FromUrl(new MongoUrl("mongodb://dev:pass#192.168.0.163/authDb?connect=direct"));
settings.MaxConnectionIdleTime = TimeSpan.FromSeconds(5);
settings.MaxConnectionPoolSize = 1000;
settings.MinConnectionPoolSize = 30;
if (config.ActiveLogMongoQueries)
{
settings.ClusterConfigurator = (cb) =>
{
cb.Subscribe<CommandStartedEvent>(
(e) =>
{
if (!IsServiceRequest(e.CommandName))
{
logger.LogInformation($"Mongo.Query DataBaseNameSpace: {e.DatabaseNamespace}. CommandName: {e.CommandName}. Command: {e.Command.ToString()}");
}
});
};
}
return new MongoClient(settings);
});
services.AddTransient(s =>
{
var config = s.GetService<ISettings>();
var dbName = "myDbName";
var mongoConnectionString = new MongoUrl(config.MongoConnectionString);
if (!string.IsNullOrEmpty(mongoConnectionString.DatabaseName))
{
dbName = mongoConnectionString.DatabaseName;
}
return s.GetService<IMongoClient>().GetDatabase(dbName);
});
This also works fine when I run integration tests from Visual studio IDE test runner. But when I try run test project automatic using gitlab CI, I have ConnectionTimeoutExeption:
System.AggregateException : One or more errors occurred. (A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Direct", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "192.168.0.163:27017" }", EndPoint: "192.168.0.163:27017", State: "Disconnected", Type: "Unknown" }] }.) (The following constructor parameters did not have matching fixture data: MongoDatabaseFixture fixture)
---- System.TimeoutException : A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Direct", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "192.168.0.163:27017" }", EndPoint: "192.168.0.163:27017", State: "Disconnected", Type: "Unknown" }] }.
---- The following constructor parameters did not have matching fixture data: MongoDatabaseFixture fixture
Stack Trace:
----- Inner Stack Trace #1 (System.TimeoutException) -----
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
at MongoDB.Driver.MongoDatabaseImpl.UsingImplicitSession(Action`1 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoDatabaseImpl.DropCollection(String name, CancellationToken cancellationToken)
at IntegrationTests.MongoDatabaseFixture.DropPreviousTestData() in /builds/project/project-main/project.IntegrationTests/MongoDatabaseFixture.cs:line 40
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----
My test stage in gitlab-ci.yml looks like this:
integrationtests:
image: microsoft/aspnetcore-build:1.0-2.0
stage: integrationtests
script:
- dotnet test -c Release ./$PROJECT_NAME.IntegrationTests/$PROJECT_NAME.IntegrationTests.csproj
tags:
- docker
only:
- schedules
Host machine 192.168.0.163 OS is Ubuntu and it also contains some other docker containers like clickhouse and no problems with connect to them while test runs on gitlab runner.
I try update MongoDb.Driver to latest version 2.7.2 and it solves problem. But for some reasons better for me not to update driver version.
I think, if code throws no exceptions when its works from runned application then same code also works fine from tests?
Any ideas to avoid this problem without update MongoDb library and
why it happens? I also see this post Connection times out after upgrading MongoDB.Driver from 2.7.0 to 2.7.1
But if the problem is with the driver, why does the application works correctly with old Mongo.Driver library?
Big thanks!
Updated: Today i try reproduse steps (if I put it correctly) , executed by gitlab runner. I build same image locally and run it with docker on my PC.
I use following .Dockerfile for build:
FROM microsoft/aspnetcore-build:1.0-2.0 as base
WORKDIR /app
EXPOSE 80
FROM base AS final
WORKDIR /Test
COPY ./Test /Test
ENTRYPOINT /bin/bash
Where "Test" is my solution folder. Next, i go into container using the following command:
docker run -it 2da12ce6cb7d
(name assigned by docker after build cmd) and try execute
- dotnet test -c Release ./ProjectName.IntegrationTests/ProjectName.IntegrationTests.csproj
and got these exception again. So, because my runned application (where connection is ok) used microsoft/aspnetcore:2.0.3 docker image as base the problem is probably in it.
I suddenly get errors while running the unit test for C# program in visual studio.
I guess the error appears after I added the System.Numerics.Vectors NuGet package, howewert the test I run does not use it yet.
Before adding it, the test run was fine.
I get following error:
for more details on managing these settings.
[1/13/2018 6:37:32 PM Informational] Test Adapter for Google Test: Test discovery starting...
[1/13/2018 6:37:32 PM Error] ERROR: Exception while discovering tests: System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at GoogleTestAdapter.DiaResolver.PeParser.<>c__DisplayClass4_0.<ProcessImports>b__0(LoadedImage image)
at GoogleTestAdapter.DiaResolver.PeParser.ParsePeFile(String executable, ILogger logger, Action`1 action)
at GoogleTestAdapter.DiaResolver.PeParser.ProcessImports(String executable, ILogger logger, Func`2 predicate)
at GoogleTestAdapter.DiaResolver.PeParser.FindImport(String executable, String import, StringComparison comparisonType, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.IsGoogleTestExecutable(String executable, String customRegex, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.<>c__DisplayClass6_0.<DiscoverTests>b__0()
at GoogleTestAdapter.Settings.SettingsWrapper.ExecuteWithSettingsForExecutable(String executable, Action action, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.DiscoverTests(String executable, ITestFrameworkReporter reporter, SettingsWrapper settings, ILogger logger, IDiaResolverFactory diaResolverFactory)
at GoogleTestAdapter.GoogleTestDiscoverer.<>c__DisplayClass5_0.<DiscoverTests>b__1()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at GoogleTestAdapter.Helpers.Utils.SpawnAndWait(Action[] actions, Int32 timeoutInMs)
at GoogleTestAdapter.GoogleTestDiscoverer.DiscoverTests(IEnumerable`1 executables, ITestFrameworkReporter reporter)
at GoogleTestAdapter.TestAdapter.TestDiscoverer.DiscoverTests(IEnumerable`1 executables, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
---> (Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object.
at GoogleTestAdapter.DiaResolver.PeParser.<>c__DisplayClass4_0.<ProcessImports>b__0(LoadedImage image)
at GoogleTestAdapter.DiaResolver.PeParser.ParsePeFile(String executable, ILogger logger, Action`1 action)
at GoogleTestAdapter.DiaResolver.PeParser.ProcessImports(String executable, ILogger logger, Func`2 predicate)
at GoogleTestAdapter.DiaResolver.PeParser.FindImport(String executable, String import, StringComparison comparisonType, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.IsGoogleTestExecutable(String executable, String customRegex, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.<>c__DisplayClass6_0.<DiscoverTests>b__0()
at GoogleTestAdapter.Settings.SettingsWrapper.ExecuteWithSettingsForExecutable(String executable, Action action, ILogger logger)
at GoogleTestAdapter.GoogleTestDiscoverer.DiscoverTests(String executable, ITestFrameworkReporter reporter, SettingsWrapper settings, ILogger logger, IDiaResolverFactory diaResolverFactory)
at GoogleTestAdapter.GoogleTestDiscoverer.<>c__DisplayClass5_0.<DiscoverTests>b__1()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()<---
can someone give me advice pls?
To see it, it is enough to do :
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Console.WriteLine("hello");
}
}
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.
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();
}))
};
I have a project with different layers: web, services, model, data each one has a different project in the same solution. The application, compiles and runs OK. But when I tried to implement migration I got the following error
dnx . ef migration add MigrationFile
System.InvalidOperationException: No DbContext was found. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
at Microsoft.Data.Entity.Commands.ContextTool.SelectType(IEnumerable`1 types, String name)
at Microsoft.Data.Entity.Commands.MigrationTool.GetContextType(String name)
at Microsoft.Data.Entity.Commands.MigrationTool.AddMigration(String migrationName, String contextTypeName, String startupAssemblyName, String rootNamespace,String projectDir)
at Microsoft.Data.Entity.Commands.Program.<>c__DisplayClass12_0.<AddMigration>b__0()
at Microsoft.Data.Entity.Commands.Program.Execute(String startupProject, Func`1 invoke)
at Microsoft.Framework.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host,String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
at dnx.host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
I'm using this answer as a reference.
Maybe your project has more than one DbContext or you have not turned on the migrations.
If you have more than one Context, you will want to enable and add migrations for each Context separately:
add-migration -ConfigurationTypeName MyProject.MigrationsFolder.Configuration "migrationName"
This code will add a new Migration based on your Context and using the Configuration class associated to it. The following code will update the database associated with the Configuration class.
update-database -ConfigurationTypeName MyProject.MigrationsFolder.Configuration
the commands must be like this
- dnu restore
cd the project which contain the context path
dnx . ef migration add -c ContextName - s StartupProjectName
try it and if this work let me know, thnx ^^