Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service installation attempt gives Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. #104

Open
williamrschmidt opened this issue Sep 10, 2018 · 4 comments

Comments

@williamrschmidt
Copy link

I am working in VS 2017, and I create a new console app in .Net Core 2.1. I use the nuget package manager to add PeterKottas.DotNetCore.WindowsService to my dependencies. Then I paste your example into Program.cs:

using System;
using System.Runtime;

using PeterKottas.DotNetCore.WindowsService;
using PeterKottas.DotNetCore.WindowsService.Interfaces;

namespace KottasTest
{
class Program
{
static void Main(string[] args)
{
ServiceRunner.Run(config =>
{
var name = config.GetDefaultName();
config.Service(serviceConfig =>
{
serviceConfig.ServiceFactory((extraArguments, x) =>
{
return new ExampleService();
});
serviceConfig.OnStart((service, extraArguments) =>
{
Console.WriteLine("Service {0} started", name);
service.Start();
});

                serviceConfig.OnStop(service =>
                {
                    Console.WriteLine("Service {0} stopped", name);
                    service.Stop();
                });

                serviceConfig.OnInstall(service =>
                {
                    Console.WriteLine("Service {0} installed", name);
                });

                serviceConfig.OnUnInstall(service =>
                {
                    Console.WriteLine("Service {0} uninstalled", name);
                });

                serviceConfig.OnPause(service =>
                {
                    Console.WriteLine("Service {0} paused", name);
                });

                serviceConfig.OnContinue(service =>
                {
                    Console.WriteLine("Service {0} continued", name);
                });

                serviceConfig.OnShutdown(service =>
                {
                    Console.WriteLine("Service {0} shutdown", name);
                });

                serviceConfig.OnError(e =>
                {
                    Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message);
                });
            });
        });
    }
}

public class ExampleService : IMicroService
{
    public void Start()
    {
        Console.WriteLine("I started");
    }

    public void Stop()
    {
        Console.WriteLine("I stopped");
    }
}

}

This runs as a console application, but when I attempt to install using the console (running as admin), it fails as shown below:

=============================
Microsoft Windows [Version 10.0.17134.254]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>cd C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1

C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1>KottasTest.dll action:install

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1>

If I add an app.config file such as below, to try to do a binding redirect, the result is still an error.

to try a binding redirect to the version of System.Runtime that I see in my nuget packages folder (under my profile), which is 4.3.0.0, it fails as shown below:

=============================
Microsoft Windows [Version 10.0.17134.254]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>cd C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1

C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1>KottasTest.dll action:install

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
--- End of inner exception stack trace ---

C:\AdTech\Repos\KottasTestSolution\KottasTest\bin\Debug\netcoreapp2.1>

Because the sample app is so simple, I am not sure what can be going on here. This seems very weird.

Thanks for any help you can offer.

@williamrschmidt
Copy link
Author

P.S. I do not know why my description got formatted so oddly. Also I put in the xml of the app.config file but that seems to have disappeared from the description (maybe it doesn't like xml?).

For the record I will try pasting that in again;

@williamrschmidt
Copy link
Author

Did not know that "close and comment" meant "close the whole issue." Sorry.

@williamrschmidt
Copy link
Author

williamrschmidt commented Sep 10, 2018

Here is the whole solution.

KottasTestSolution.zip

@SebastianBienert
Copy link

From Readme:
20. "Install the service using powershell: dotnet.exe $serviceDllPath action:install"
You can also try dotnet run action:install from project folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants