Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Unable to Load Assembly in Worker Service (.Net Core3.1 and NLog 4.9.2)

$
0
0

This is a repeated question but don't know what happens in this solution scenario , We are setting up an WorkerService in .Net core 3.1. For logging we are using NLog. While building we were getting the error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'. The system cannot find the file specified.'

This error occues in Project.cs(shown in code below). The ServiceFileLogger belongs to another Library Class.(folder struncture is shown below)

enter image description here

enter image description here

Project.cs

public static void Main(string[] args)        {            CreateHostBuilder(args).Build().Run();        }        public static IHostBuilder CreateHostBuilder(string[] args) =>            Host.CreateDefaultBuilder(args)           .UseWindowsService()                .ConfigureServices((hostContext, services) =>                {                    IConfiguration config = hostContext.Configuration;                    services.AddSingleton<IConfiguration>(config);                    services.AddSingleton<ServiceSettings>(config.GetSection("Application").Get<ServiceSettings>());// Error comes here during the injection.                    services.AddTransient<ServiceFileLogger>(_logger=> new ServiceFileLogger("DATASOURCEMONITOR", config.GetSection("Application:LogLevel").ToString()));                    services.AddHostedService<Worker>();                });    }}

We even changed the Nlog version 4.9.2 to NLog version 4.9.0 ()More Info

<Project Sdk="Microsoft.NET.Sdk.Worker"><PropertyGroup><TargetFramework>netcoreapp3.1</TargetFramework><UserSecretsId>dotnet-WorkerServiceLearn-817A165A-A227-4F73-ABBC-EE79E10DE8A3</UserSecretsId><ApplicationIcon /><OutputType>Exe</OutputType><StartupObject /></PropertyGroup><ItemGroup><PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" /><PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.5" /><PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" /></ItemGroup><ItemGroup><Reference Include="WorkerServiceLearn.Library"><HintPath>..\WorkerServiceLearn.Library\bin\Debug\netcoreapp3.1\WorkerServiceLearn.Library.dll</HintPath></Reference></ItemGroup></Project>

Don't know what to change here, kindly help us and provide some documents to validate.

Repository Link is here, kindly go through it and advice us.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>