c# - Windows 服务 : System. Reflection.ReflectionTypeLoadException 被抛出并出现以下错误消息:无法加载一个或多个重新

标签 c# windows-services assembly-loading

我正在使用 Windows 服务,其中我有一个程序集的引用,该程序集是 copy local= false。但是我试图在运行时加载它,虽然当我从 visual studio 运行它时工作正常,但是当我尝试安装它时,cmd 给出了这个错误:

An exception occurred while trying to find the installers in the D:\Official\Pro
jects\20131007_ImproveDN\build\debug\application
s\SubscriptionService\SubscriptionService.exe assembly.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the
 requested types. Retrieve the LoaderExceptions property for more information.
Aborting installation for D:\Official\Projects\2
0131007_ImproveDN\build\debug\applications\SubscriptionService\SubscriptionServi
ce.exe.
An exception occurred during the Rollback phase of the System.Configuration.Inst
all.AssemblyInstaller installer.
System.InvalidOperationException: Unable to get installer types in the D:\Offici
al\Projects\\20131007_ImproveDN\build\debug\appli
cations\SubscriptionService\SubscriptionService.exe assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown wit
h the following error message: Unable to load one or more of the requested types
. Retrieve the LoaderExceptions property for more information..
An exception occurred during the Rollback phase of the installation. This except
ion will be ignored and the rollback will continue. However, the machine might n
ot fully revert to its initial state after the rollback is complete.

这里还需要注意的一件事是,如果我将该 .dll 复制到本地,则可以正常安装。但是我不想在安装之前加载它,所以我想在运行时加载它。

提前致谢。

最佳答案

也许您需要使用另一个版本的 InstallUtil.exe:

  • c:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe
  • c:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
  • c:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe
  • c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe

尝试使用 Framework64 子文件夹中的 x64 版本。

关于c# - Windows 服务 : System. Reflection.ReflectionTypeLoadException 被抛出并出现以下错误消息:无法加载一个或多个重新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19360378/

相关文章:

python - "Error 1053: The service did not respond timely",无法从 Python 代码启动使用 cx_Freeze 创建的 Windows 服务

c# - Windows 服务中的无限 while 循环

c# - 无法加载文件或程序集 'Microsoft.OpenApi' ... 使用 Swashbuckle.AspNetCore.Cli 时

C# 无法启动系统 EXE 进程

c# - ObservableCollection<T> 中的 block 重入

c# - Razor 类库中的图像

c# - 使用 Assembly.Load 是静态引用还是动态引用?

c# - SRI 散列不是预期的

c# - 无法借助InstallUtil工具安装windows服务

nunit - TeamCity NUnit 运行程序因 x86 - x64 - MSIL 差异而失败