Question

I have a windows service that is written in .NET, and i used probing feature in order to load dll's to this windows service. However, when i open command prompt and try to install windows service using installutil.exe, i got an error such as: "System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. Aborting installation for",

On the other hand, when i move dll's in the same folder with windows service and repeat the installation procedure, windows service is installed successfully.

Do you have any ideas or suggestions about this problem?, is there a probing problem in windows service installation of .NET?

No correct solution

OTHER TIPS

I face the same problem in my project, in my windows service project i have the following app.config section:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="SDK" />
    </assemblyBinding>
</runtime>

if i executed the service as a console all is well, but when i try to install it the installutil failed and i got the same exception, so my solution is made the service installed itself by a command line: like so:

cmd: hotspotcenter -i <service_name="service name">
// service_name i made it optional

the Installer class helper:

internal static class BasicServiceInstaller
{
    public static void Install(string serviceName)
    {
        CreateInstaller(serviceName).Install(new Hashtable());
    }

    public static void Uninstall(string serviceName)
    {
        CreateInstaller(serviceName).Uninstall(null);
    }

    private static Installer CreateInstaller(string serviceName)
    {
        var installer = new TransactedInstaller();
        installer.Installers.Add(new ServiceInstaller
        {
            ServiceName = serviceName,
            DisplayName = serviceName,
            StartType = ServiceStartMode.Manual
        });
        installer.Installers.Add(new ServiceProcessInstaller
        {
            Account = ServiceAccount.LocalSystem
        });
        var installContext = new InstallContext(
            serviceName + ".install.log", null);
        installContext.Parameters["assemblypath"] =
            Assembly.GetEntryAssembly().Location;
        installer.Context = installContext;
        return installer;
    }
}

in the main entry of the service project:

 if (Environment.UserInteractive)
 {
            bool install = false;
            bool uninstall = false;
            string serviceName = "YourDefaultServiceName";

            var p = new OptionSet()
              .Add<bool>("i|install", "Install Windows Service", i => install = i)
              .Add<bool>("i|install=", "Install Windows Service", i => install = i)
              .Add<bool>("u|uninstall", "Uninstall Window Service", u => uninstall = u)
              .Add<string>("sn|service_name=", "Service Name", n => serviceName = n);

            p.Parse(args);

            if (install)
            {
                BasicServiceInstaller.Install(serviceName);
                return;
            }
            else if (uninstall)
            {
                BasicServiceInstaller.Uninstall(serviceName);
                return;
            }

            // if no install or uninstall commands so start the service as a console.
            var host = new YourService();
            host.Start(args);
            Console.ReadKey();
        }
        else
        {
            ServiceBase.Run(new HotspotCenterService());
   }

Without exact information, I would suggest following:

  • check the exception details to see what exactly went wrong
  • use Fusion Log Viewer, to see which assemblies failed binding
  • check whether your probing configuration matches your deployment

Probing is configured as described here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top