该项目已使用 NHibernate 3.3.1 编译(据我所知 - 我可能是错的,但是当我创建一个 2.0.4 SharpArch 项目时,它通过 Nuget 下载了 NH 3.3.1)。
为什么Visual Studio将NHibernate显示为版本3.3.1.4000,而引用的dll是3.3.2.4000?对于所有引用,"特定版本"属性都设置为 false。SharpArch的版本出现在VS 2.0.0.0中,而不是文件/产品版本的2.0.4。
在应用程序配置中,我有:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.4000" newVersion="3.3.2.4000" />
</dependentAssembly>
</assemblyBinding>
</runtime>
应用无法加载,并显示:
System.IO.FileLoadException was unhandled
Message=Could not load file or assembly 'NHibernate, Version=3.3.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=MyApp.ResourcesGenerator
FileName=NHibernate, Version=3.3.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
FusionLog=""
StackTrace:
at MyApp.ResourcesGenerator.Program.InitializeNHibernateSession()
at SharpArch.NHibernate.NHibernateInitializer.InitializeNHibernateOnce(Action initMethod) in d:BuildsSharpArch2SolutionsSharpArch.NHibernateNHibernateInitializer.cs:line 54
at MyApp.ResourcesGenerator.Program.Initialize() in C:projectstcTrunkSource_LibsUpgradeApplicationsPerformanceManagementMyApp.ResourcesGeneratorProgram.cs:line 149
at MyApp.ResourcesGenerator.Program.Main(String[] args) in C:projectstcTrunkSource_LibsUpgradeApplicationsPerformanceManagementMyApp.ResourcesGeneratorProgram.cs:line 31
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileLoadException
Message=Could not load file or assembly 'NHibernate, Version=3.3.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
FileName=NHibernate, Version=3.3.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
我什至不确定为什么当使用 3.3.1 编译清晰的架构时,它为什么要尝试加载 3.3.0.4000。
NHibernate 3.3.2.GA 的文件版本为 3.3.2.4000,但程序集版本仍为 3.3.1.4000。这样做是为了允许升级 NHibernate,而无需绑定重定向。NHibernate的所有未来次要版本升级也将遵循此模式。
因此,您的解决方案就是删除绑定重定向。
这里令人困惑的部分是Windows资源管理器仅显示文件和产品版本,而Visual Studio仅显示程序集版本。