我正在使用VS 2015 Update 2和Resharper Ultimate 2016.1,我有这个奇怪的问题。Assembly.LoadFrom不会从bin debug加载dll时使用resharper运行单元测试
我有一个名为Test的测试项目,它引用了两个项目Model和Persistence。模型项目包含nhibernate实体类,并且Persistence项目包含* .hbm.xml文件。它们是用llblgenpro 4.2生成的。我使用的是nhibernate 4.0.4。
我初始化NHibernate的这个电话:
NHibernateSession.Init(
new SimpleSessionStorage(),
new string[] { "Persistence.dll", "Model.dll" });
当我跑我的测试用例一个NHibernate的初始化失败与此异常:
System.IO.FileNotFoundException was unhandled by user code
FileName=file:///C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll
FusionLog==== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll
LOG: Appbase = file:///C:/projects/csharp/Test/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\costa\AppData\Local\Temp\s0hjyhsk.jq1\a3514fde-acb9-4c62-a0ce-a586f8202f35.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Users/costa/AppData/Local/JetBrains/Installations/ReSharperPlatformVs14/Persistence.dll.
HResult=-2147024894
Message=Could not load file or assembly 'file:///C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll' or one of its dependencies. The system cannot find the file specified.
Source=mscorlib
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at SharpArch.NHibernate.NHibernateSession.<>c__DisplayClass36_0.<CreateSessionFactoryFor>b__0(MappingConfiguration m) in C:\work\sharp-arch\Solutions\SharpArch.NHibernate\NHibernateSession.cs:line 412
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
InnerException:
如果我的persistence.dll复制到C:\ Users \ costa \ AppData \ Local \ JetBrains \ Installations \ ReSharperPlatformVs14文件夹中,测试用例正常工作。 persistence.dll位于C:/ projects/csharp/Test/bin/Debug文件夹中,因为持久性项目在测试项目中被引用。
这一切在VS 2013与nhibernate 3.3.1罚款。此外,我得到所有的DLL版本使用测试项目app.config文件中的assemblybinding元素对齐。
我的项目的目标.net 4.6和我使用nunit 3.2.1。
我发现这一点:
Resharper runs UnitTest from different location
然而,在我的情况“影复制组件正在测试”被关闭,使用单独的AppDomain中的每个组件,测试也被关闭。运行测试从设置为项目输出文件夹。
任何想法可能导致这种情况?
感谢
更新:如果我这样做,它的工作原理:
string path = Assembly.GetExecutingAssembly().Location;
string directory = Path.GetDirectoryName(path);
NHibernateSession.Init(
new SimpleSessionStorage(),
new string[] { directory + "\\Persistence.dll", directory + "\\Model.dll" });
更新2.我的项目使用Sharp Architecture library。 NHibernateSession是一个属于这个库的类。
什么是NHibernateSession?它不视我为NHibernate的本地部分。如果这是一些自定义类,那么很难在没有代码的情况下帮助你。也许这是由llblgenpro生成的一些类:在这种情况下请求他们支持可能会更好。 –
也许你会更容易将llblgenpro放在一旁,并直接与你的映射和会话工厂一起工作。它可以让你微调他们的业务需求。 (你可以阅读更多关于我的观点[这里](/ a/35589532/1178314)。)你将有更多的选择来处理你的会话工厂初始化,例如我的答案[here](/ a/35711701/1178314)。 –
@Frédéric:我更新了我的帖子。该NHibernateSession属于s#arp-architecture库。对不起,我错过了这个。 – costa