【发布时间】:2022-12-10 07:23:00
【问题描述】:
我通过运行 dotnet publish -r osx-arm64 为我的 dotnet 项目创建了一个安装程序。但是,当我尝试运行可执行文件时,它看起来确实在http://localhost:5000 上启动了服务器。
这是日志:
Starting C-Store SCP server on port 11112
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
但是,由于我的 GET 端点从本地 mongo 服务器获取数据,因此当我尝试运行 GET 端点 http://localhost:5000/api/getItems 时,它会抛出一个错误,如下所示
Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "XXXXXXX", Request id "XXXXX": An unhandled exception was thrown by the application.
System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName)
at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString, Boolean isInternalRepresentation, IDnsResolver dnsResolver)
at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString)
at MongoDB.Driver.MongoUrlBuilder.Parse(String url)
at MongoDB.Driver.MongoUrlBuilder..ctor(String url)
at MongoDB.Driver.MongoUrl..ctor(String url)
at MongoDB.Driver.MongoClientSettings.FromConnectionString(String connectionString)
at MongoDB.Driver.MongoClient..ctor(String connectionString)
我假设这是因为可执行文件中没有 mongodb 服务器/驱动程序?
我需要一些关于如何在可执行文件中包含 mongodb 服务器的建议,一旦我运行可执行文件,它就会自动启动。我的总体目标是为我的 dotnet 项目创建一个可执行文件,其中包含一个带有它的 mongo 服务器。谢谢!
【问题讨论】:
-
这是因为连接字符串为空
-
我的发布文件夹中的
appsettings.json是:``` { "RouterDatabase": { "ConnectionString": "mongodb://localhost:27017", "DatabaseName": "XXX", "ApiEndpointsCollectionName": "XXX" }, “日志记录”:{“LogLevel”:{“默认”:“信息”,“Microsoft.AspNetCore”:“警告”}},“AllowedHosts”:“*”}``` -
idk,看起来你做错了什么,但错误很明显,只说错过了连接字符串
标签: c# .net mongodb .net-core executable