[英]Probing Load Exception While Installing Windows Service On .NET
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. 我有一个用.NET编写的Windows服务,并且我使用了探测功能,以便将dll加载到该Windows服务中。 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", 但是,当我打开命令提示符并尝试使用installutil.exe安装Windows服务时,出现诸如以下错误:“ System.Reflection.ReflectionTypeLoadException:无法加载一个或多个请求的类型。获取LoaderExceptions属性以获取更多信息。正在中止安装,“,
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. 另一方面,当我将dll移到Windows服务所在的同一文件夹中并重复安装过程时,Windows服务已成功安装。
Do you have any ideas or suggestions about this problem?, is there a probing problem in windows service installation of .NET? 您对此问题有任何想法或建议吗?.NET的Windows服务安装中是否存在探测问题?
Without exact information, I would suggest following: 如果没有确切的信息,我建议以下几点:
Probing is configured as described here . 探测按此处所述进行配置。
I face the same problem in my project, in my windows service project i have the following app.config
section: 我在我的项目中遇到相同的问题,在Windows服务项目中,我有以下app.config
部分:
<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: 如果我通过控制台执行该服务,一切都很好,但是当我尝试安装它时,installutil失败,并且出现了相同的异常,因此我的解决方案是通过命令行将服务本身安装起来:
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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.