2015-04-17 22 views
1

我遇到了一個測試WPF應用程序的錯誤,我正在使用它學習Prism。錯誤日誌在下面,但其要點是,它似乎無法找到Microsoft.Practices.Unity版本3.5.1.0。根據我的理解,這可能意味着兩件事情:要麼找不到Unity的任何版本,要麼發現Unity的版本號錯誤。如何解決「無法加載文件或程序集」Microsoft.Practices.Unity「錯誤?

爲了排除第一個選項(至少我相信這會排除)我再次檢查dll安裝在需要它的項目和bin文件夾中;每個項目和bin文件夾中只有一個Unity副本。它已安裝,但根據屬性描述,它說版本是3.5.0.0。根據對象瀏覽器,它表示該DLL位於名爲「Unity.3.5.1404.0」的文件夾中。請注意,DLL是使用NuGet安裝的,而我安裝的兩組軟件包稱爲「Prism」和「Prism.UnityExtensions」。這是Unity dll的第二個。

有趣的是,我實際上開始了一個新的教程項目,看它是否能解決問題,並從原始項目中複製了一些項目。我能夠第一次編譯和運行它,但是後來我從App.config文件中取出了下面的代碼段,以查看會發生什麼(愚蠢的錯誤...)並開始出現相同的錯誤。這甚至在我將它添加回App.config文件後。請注意,下面的代碼在創建項目時位於App.config文件中;這不是我以後親自添加的內容。

是否有其他地方我應該尋找可能會導致問題的流氓Unity dll?有什麼我需要添加或刪除,使目前的統一DLL的工作?


代碼,其中的錯誤正在發生(上bootstrapper.Run;這是在App.xaml.cs):

protected override void OnStartup(StartupEventArgs e) 
    { 
     base.OnStartup(e); 

     Bootstrapper bootstrapper = new Bootstrapper(); 
     bootstrapper.Run(); 
    } 

代碼:

<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Practices.Prism.SharedInterfaces" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.5.1.0" newVersion="3.5.1.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

錯誤:

System.IO.FileLoadException was unhandled HResult=-2146234304 Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source=Microsoft.Practices.Prism.UnityExtensions FileName=Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 FusionLog="" StackTrace: at Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration) at Microsoft.Practices.Prism.Bootstrapper.Run() at EmailClient.App.OnStartup(StartupEventArgs e) in c:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\App.xaml.cs:line 21 at System.Windows.Application.<.ctor>b__1(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at EmailClient.App.Main() in c:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\obj\Debug\App.g.cs:line 50 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.IO.FileLoadException HResult=-2146234304 Message=Could not load file or assembly 'Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) FileName=Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 FusionLog==== Pre-bind state information === LOG: DisplayName = Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/Users/Roger/Google Drive/Karnaluks/Test Projects/EmailClient/EmailClient/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.Practices.Prism.UnityExtensions, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\Roger\Google Drive\Karnaluks\Test Projects\EmailClient\EmailClient\bin\Debug\EmailClient.vshost.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 3.5.0.0 redirected to 3.5.1.0. LOG: Post-policy reference: Microsoft.Practices.Unity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/Roger/Google Drive/Karnaluks/Test Projects/EmailClient/EmailClient/bin/Debug/Microsoft.Practices.Unity.DLL. WRN: Comparing the assembly name resulted in the mismatch: Build Number ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

InnerException: 

回答

0

您是否嘗試過清潔和重建解決方案?也許卸載軟件包然後再安裝它們將會有所幫助。安裝Nuget包時會添加app.xaml代碼。

+0

嘿,謝謝你的回覆。我只是嘗試了清潔和重建解決方案,但卻遇到了同樣的情況。我卸載並安裝了幾次軟件包,然後再次嘗試。通過NuGet包添加的代碼,我得到了與我在文章中提到的相同的錯誤,但是隨着它刪除,程序得到進一步並創建一個窗口,但隨後崩潰,出現了我以前處理的錯誤(http:// stackoverflow.com/questions/29537911/how-to-resolve-could-not-load-file-or-assembly-microsoft-practices-prism-er),我永遠不能修復。有點難倒了。 –

+0

遇到完全相同的問題。試了幾件事,包括上面提到的建議。 –

+0

如果你找到一個修復邁克,讓我知道!我的搜索沒有領先在哪裏。 –

相關問題