2
votes

I'm trying to run a dotnet core WebApi on a MacOs. Running the project with dotnet run works fine, since it runs from source code.

Now i want to pack the Api and run it on other machine, so for that i use the following command

dotnet publish WebApiX.sln -f netcoreapp2.0 -c Release -o ../output -r osx.10.12-x64

which packs the whole application and their dependencies. After this i want to start the web server with dotnet WebApiX.Api.dll but i'm getting the following error:

Unhandled Exception: System.ArgumentNullException: Value cannot be null. Parameter name: pathFormat at Microsoft.Extensions.Logging.FileLoggerExtensions.AddFile(ILoggerFactory loggerFactory, String pathFormat, LogLevel minimumLevel, IDictionary`2 levelOverrides, Boolean isJson, Nullable`1 fileSizeLimitBytes, Nullable`1 retainedFileCountLimit)

This exception is generated in Configure method presented on Startup class

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // Configure Midleware
    loggerFactory.AddFile(Configuration.GetSection("LogsLocation").Value);

    app.UseMiddleware<SerilogMiddleware>();
    app.UseMiddleware<ErrorWrappingMiddleware>();

    app.UseAuthentication(); 
    app.UseMvc();
}

For testings purposes i tried to remove the line LoggerFactory.. and its strange because the error now is different.

Unhandled Exception: System.InvalidOperationException: Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
   at WeidertAuth.Api.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in /Users/mariomarques/Documents/Avnoconn/Projects/WEIDERT/WeidertServices/weidert.auth/WeidertAuth.Api/Startup.cs:line 249
1
Try publishing with Debug configuration and see if error persists. - Erndob
it may help if you share that part of the code where you use .AddFile method - Set
Running with debug configuration results in the same thing. I guess its something related to Configurations. Question is edited to include the Configure method presented on Startup class (which is the method that originates the exception) - mmarques
Can you share the related section in your appSettings file? Configuration.GetSection will be looking for a section called "LogsLocation", if that doesn't have a value then that could be where the issue lies - Jamie Taylor
I've ensured it has a value. In fact i removed that line and now the error is different - mmarques

1 Answers

0
votes

you should add a runtime identifier to project file (.csproj), like the following:

<RuntimeIdentifiers>osx.10.12-x64</RuntimeIdentifiers>

Once done, you should restore the project and publish it using cmd:

dotnet restore

// publish for macos
dotnet publish -r osx.10.12-x64 --output bin/dist/osx

Then you can find an executable of the project within project at the following path:

MyProject/bin/dist/osx

Hope you'll find this useful.