Hi @Fabig, Richard , Welcome to Microsoft Q&A,
Judging from the error message, it is caused by the Windows service not being able to find the System.Diagnostics.EventLog
assembly when starting.
Ensure that all project dependencies are properly deployed to the server. In particular, the System.Diagnostics.EventLog
assembly and other assemblies it may depend on. You can ensure that all necessary files are included by setting PublishSingleFile
and IncludeAllContentForSelfExtract
in your project.
<PropertyGroup>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup>
Make sure that the version of System.Diagnostics.EventLog matches the version in the error message. Explicitly specify the required version in your project file (.csproj).
<ItemGroup>
<PackageReference Include="System.Diagnostics.EventLog" Version="6.0.0" />
</ItemGroup>
Verify that the System.Diagnostics.EventLog.dll file does exist in the deployment directory. If you are using a publish folder, you can manually check if the file exists.
Make sure the Windows service account has permission to write to the event log. You can specify a user account with appropriate permissions in the service configuration to run the service.
Ensure all NuGet packages are restored correctly before building and publishing. You can use the Restore NuGet Packages option in Visual Studio.
Make sure the .NET 6 runtime is properly installed on your test server. You can try reinstalling or updating to the latest version.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.