1. Marco Meoni
  2. SnapDevelop
  3. Monday, 29 June 2020 07:21 AM UTC

Hello,
Im running from Snap 2019 R2 #2323 the simplest datastore WebApi and performing the simplest GET from browser:

http://localhost:5000/api/department/retrieve

all ok. 
When running from command prompt instead (same machine, same DB, same .NET core, same all)

C:\Program Files\dotnet\dotnet.exe .\WebApi\bin\Debug\netcoreapp2.1\WebApi.dll

the WebApi starts same way as in Snap console

Now listening on: http://localhost:5000

but the GET returns unhandled exception below.
C# forums suggest to upgrade to Microsoft.AspNetCore.App 2.2 (not willing to, as Snap #2323 depends on 2.1) or check https/http mismatch (not my case). Cant recall if I had same issue on Snap 2019 R1.

Any idea?
Best,
.m


info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/api/department/retrieve
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
Route matched with {action = "Retrieve", controller = "Department"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.ActionResult`1[DWNet.Data.IDataStore`1[WebApi.Models.Department]] Retrieve() on controller WebApi.Controllers.DepartmentController (WebApi).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action WebApi.Controllers.DepartmentController.Retrieve (WebApi) in 10.768ms
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM0QM45DVLJ2", Request id "0HM0QM45DVLJ2:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: Invalid connection string.
at SnapObjects.Data.AdoDbConnection..ctor(String connectionString)
at SnapObjects.Data.SqlServer.SqlServerDataContext.CreateAdoDbConnection(String connectionString)

Accepted Answer
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 1 July 2020 15:36 PM UTC
  2. SnapDevelop
  3. # Permalink

Hi Marco,

It seems that dotnet.exe failed to find your appsettings.json or appsettings.production.json.

Please run the dotnet command in the folder where your appsettings files are located. Then it will read your connection string correctly.

Regards,

Logan

 

Comment
  1. Marco Meoni
  2. Wednesday, 1 July 2020 20:56 PM UTC
Thank you Logan,

indeed problem was the path, appsettings is in .\WebApi and therefore the execution had to be



C:\Program Files\dotnet\dotnet.exe .\bin\Debug\netcoreapp2.1\WebApi.dll



Best,

.m
  1. Helpful
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 1 July 2020 15:08 PM UTC
  2. SnapDevelop
  3. # 1

Hi Marco,

 

Please make sure you have both the .NET Core SDK and Runtimes. Also, try doing a successful CLEAN, BUILD and REBUILD of the solution.

 

The error you are getting is pointing to a wrong connection string to your Database. You might also want to take a look into that.

 

Please do let me know if this helped.

 

Regards,

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.