Mat-Tap
Mat-Tap

Reputation: 755

Hosting a Console application in Service Fabric

I'm starting with Service Fabric. I have created a very simple console application that runs the following code:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello world!");
        File.AppendAllText("c:\\temp\\hello.txt", "Hello world!" + DateTime.Now.ToString() + "\r\n");
        Console.ReadLine();
    }
}

Then I create a guest executable project with Visual Studio and point it to the exe application. It gets installed in Service Fabric, I can see that the file is created, but then service fabric throws an error:

Error event: SourceId='System.FM', Property='State'. Partition is below target replica or instance count. fabric:/Test3/Test3Service -1 1 5ef5a0eb-5621-4821-95cb-4c1920ab7f0c (Showing 0 out of 0 replicas. Total available replicas: 0.)

Is this approach correct? Can I have exe applications hosted in Service Fabric or do I need to implement/inherit from something?

EDIT

When the application is deployed it enters in a Warning state, showing the following messages:

Warning message

Soon afterwards it transitions to an error state:

Error message

Upvotes: 1

Views: 2110

Answers (1)

yoape
yoape

Reputation: 3325

Yes you can host a simple Console Application in Service Fabric as a Guest Executable, that should not be a problem.

The issue you are seeing is likely because the application is trying to write to a file in c:/temp where your Guest Exe by default doesnt have permissions. Try removing that part of your sample code, or change it to write to hello.txt and it will end up in the same folder your Guest Exe is running in.

You should consider file storage on a Service Fabric node as temporary however and not rely on storing data there as your service could be moved between nodes by Service Fabric as part of it's cluster maintenance.

See this answer for some more details on file system access in SF https://stackoverflow.com/a/37966158/1062217

Upvotes: 2

Related Questions