我遇到服务问题。我正在通过Advanced Installer安装文件安装该服务,安装后,它在开发服务器上运行正常。
但是,尝试在不同服务器上使用相同的安装文件安装服务时,服务在启动期间崩溃时出现以下错误消息:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
at Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveType(System.String, Boolean)
at Microsoft.Practices.Unity.Configuration.RegisterElement.GetRegisteringType()
at Microsoft.Practices.Unity.Configuration.RegisterElement.ConfigureContainer(Microsoft.Practices.Unity.IUnityContainer)
at Microsoft.Practices.Unity.Configuration.ContainerElement+<>c__DisplayClass1.<ConfigureContainer>b__0(Microsoft.Practices.Unity.Configuration.ContainerConfiguringElement)
at Microsoft.Practices.ObjectBuilder2.EnumerableExtensions.ForEach[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Action`1<System.__Canon>)
at Microsoft.Practices.Unity.Configuration.ContainerElement.ConfigureContainer(Microsoft.Practices.Unity.IUnityContainer)
at Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.Configure(Microsoft.Practices.Unity.IUnityContainer, System.String)
at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, System.String)
at Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.Configuration.UnityConfigurationSection)
at NFCommonImplementation.Factory.NfUnityContainer..ctor()
at NFCommonImplementation.Factory.NfUnityContainer.get_Instance()
at NFObjectFactory.CommonObjectFactory..ctor()
at NFObjectFactory.CommonObjectFactory.<.cctor>b__0()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateValue()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].LazyInitValue()
at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Value()
at NFDataImporter.ImportService.<Start>b__2()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
使用控制台手动启动服务文件(使用topshelf),指定错误如下:
Topshelf.Hosts.ConsoleRunHost Critical: 0 : The service threw an unhandled exception, System.InvalidOperationException: The type name or alias INetReportDao could not be resolved. Please check your configuration file and verify this type name.
我已经检查了统一配置文件,其中包含:
[...]
<typeAlias alias="INetReportDao"
type="NFCommonInterfaces.Database.DAO.INetReportDao, NFCommonInterfaces, Version=6.0.0.1, Culture=neutral, PublicKeyToken=c98e951d4a9d1d0a" />
[...]
<typeAlias alias="NetReportDao"
type="NFCommonImplementation.Database.DAO.NetReportDao, NFCommonImplementation, Version=6.0.0.1, Culture=neutral, PublicKeyToken=c98e951d4a9d1d0a" />
[...]
<register type="INetReportDao" mapTo="NetReportDao">
</register>
[...]
我还检查过NFCommonImplementation.dll和NFCommonInterfaces.dll是否位于服务可执行文件的旁边。
现在我的智慧结束了。从理论上讲,它应该可以工作,因为安装程序会在两台服务器上安装完全相同的服务版本。但是,出于某种原因,它适用于一台服务器,而不适用于另一台服务器。
可能是因为我缺少依赖关系吗?安装程序已自动识别Visual Studio 2012的Visual C ++ Redistributable依赖项并安装它。是否可能存在可能安装在开发服务器上的其他依赖项,而不是可能导致此问题的测试服务器?
答案 0 :(得分:0)
好的,经过一番调查后,我想出了如何解决这个问题,经过一番调查后,我发现了导致它的原因:
修复:
缺少的.dll必须安装到GAC中。最简单的方法是使用以下PowerShell脚本:
Set-location "[dll file location]"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("[dll file name]")
原因:
在开发服务器上,构建过程将有问题的.dll安装到自定义程序集缓存中,如果在该服务器上运行,该服务器可以访问该缓存。但是,它自然无法在任何其他服务器上找到这些文件。
我希望这可以帮助其他遇到类似困难的人。