Windows Service: System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the re

Windows Service: System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the re

问题:

The uninstall is beginning.
See the contents of the log file for the MonitorService.exe assembly's progress.
The file is located at MonitorService.InstallLog.
An exception occurred during the uninstallation of the System.Configuration.Install.AssemblyInstaller installer.
System.InvalidOperationException: Unable to get installer types in the MonitorService.exe assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..
An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be fully uninstalled after the uninstall is complete.

 

回答

Maybe you need to use another version of 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

Try to use x64 version from Framework64 subfolder.

 

不过还是推荐sc delete serviceName进行删除

 

How to retrieve the LoaderException property?

try
{
  // load the assembly or type
}
catch (Exception ex)
{
  if (ex is System.Reflection.ReflectionTypeLoadException)
  {
    var typeLoadException = ex as ReflectionTypeLoadException;
    var loaderExceptions  = typeLoadException.LoaderExceptions;
  }
}

 

posted @ 2020-07-01 18:20  ChuckLu  阅读(717)  评论(0编辑  收藏  举报