0

So ... I'm having this .net core .exe console app which ... runs a server S1.

I'd like to start the server along with another app, let's say a console C1 (console, web, could be anything). Got some help to do it using a simpe example run external .exe app, yep, but when I apply the same approach to my project, it turns out it can't find the path to the db?

Below the exception I get

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware An unhandled exception has occurred while executing the request. System.ArgumentNullException: Value cannot be null. (Parameter 'path') at Se.Cae.Application.EntityFrameworkCore.Sqlite.ApplicationDataSource..ctor(String path, SecureString password, IDataMigration migrationSvc, IDataEncryption encryptionSvc, IDataIntegrity dataIntegritySvc) at Se.Cae.Application.EntityFrameworkCore.Sqlite.ApplicationDataSource..ctor(String path, IDataMigration migrationSvc, IDataEncryption encryptionSvc, IDataIntegrity dataIntegritySvc)

Got a tip from a friend, a temporary workaround: move your appsettings.json, where the connection string of your db is configured, to the bin folder of C1.

And yeah, it works, but ... it's not a clean solution, I'd have to put the file manually in the bin folder.

Which makes me wonder, is there a trick which can makes my standalone app launch correctly (including the db) without having to "cheat" :)

Thank you

MoBe
  • 61
  • 5
  • Try setting [the `ProcessStartInfo.WorkingDirectory` property](https://learn.microsoft.com/en-gb/dotnet/api/system.diagnostics.processstartinfo.workingdirectory?view=net-6.0) to the folder that contains S1. – Richard Deeming Feb 11 '22 at 17:07
  • 1
    It sounds like you're just "copying an .exe". *DON'T DO THAT!* You need to [deploy](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/) your app. For example, if you're using MSVS, you can [Publish](https://learn.microsoft.com/en-us/visualstudio/deployment/publish-overview). BOTTOM LINE: any self-respecting "deploy tool" (e.g. "MSVS > Publish") should automatically deploy your appsettings.json - along with any other runtime dependencies - to your target. – paulsm4 Feb 11 '22 at 17:08
  • @RichardDeeming hmmm, interesting, scenario 1: async statements work fine without standalone mode, then scenario 2: I add that property line you suggested, it doesn't work, but it resolves my db problem, and scenario 3 when I only use one or two async statements rather than what I had in the first place (a lot), it works. It makes me wonder, why? The only difference between scenario 1 and 3 is one line of coooooode. Anyway, just saying it worked :) I'll try debug my code and see what's going, maybe my async com is bad (it's a complex topic, I've been warned) – MoBe Feb 14 '22 at 13:50
  • @paulsm4 But that would imply I would have to launch the server either manually, or having it always running, but ... what if I just wanna launch the server when I start my app and shut it down when closing it? Unless I lean towards a solution more related to containerization & orchestration (I'm not there yet), I don't understand why it is a bad practice/choice to be having the server (.exe with dlls) within another project. – MoBe Feb 14 '22 at 13:56
  • It's a "bad idea" to equate "deploy" with "file copy". If that's in fact what you're doing: I can't tell from your post. I'm also unclear what your "projects" (100% "development artifacts") have to do with your question (running related apps on the target system). Again: the real issue is to design and implement a viable "deployment", so that whatever you "push" from your development workstation to the target servers "just works". STRONG SUGGESTION: your "push" (your "deploy") should be *AUTOMATED* (not "manual"). – paulsm4 Feb 14 '22 at 18:50

0 Answers0