我正在使用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