2014-03-01 162 views
10

我正在開發另一個應用程序Autodesk Revit的加載項,它是作爲單獨的DLL類庫構建的。我試圖在我的WPF窗口中使用Wpf Tool Kit Property grid。屬性網格在Visual Studio中顯示效果良好,intellisense也適用。但是,當我嘗試使用加載項啓動Revit時,出現以下異常。無法加載文件或程序集Xceed.Wpf.Toolkit

System.Windows.Markup.XamlParseException occurred 
    HResult=-2146233087 
    Message=Could not load file or assembly 'Xceed.Wpf.Toolkit, PublicKeyToken=3e4669d2f30244f4' or one of its dependencies. The system cannot find the file specified. 
    Source=PresentationFramework 
    LineNumber=133 
    LinePosition=27 
    StackTrace: 
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
    InnerException: System.IO.FileNotFoundException 
     HResult=-2147024894 
     Message=Could not load file or assembly 'Xceed.Wpf.Toolkit, PublicKeyToken=3e4669d2f30244f4' or one of its dependencies. The system cannot find the file specified. 
     Source=mscorlib 
     FileName=Xceed.Wpf.Toolkit, PublicKeyToken=3e4669d2f30244f4 
     FusionLog==== Pre-bind state information === 
LOG: User = GLOBAL\eric.anastas 
LOG: DisplayName = Xceed.Wpf.Toolkit, PublicKeyToken=3e4669d2f30244f4 
(Partial) 
WRN: Partial binding information was supplied for an assembly: 
WRN: Assembly Name: Xceed.Wpf.Toolkit, PublicKeyToken=3e4669d2f30244f4 | Domain ID: 1 
WRN: A partial bind occurs when only part of the assembly display name is provided. 
WRN: This might result in the binder loading an incorrect assembly. 
WRN: It is recommended to provide a fully specified textual identity for the assembly, 
WRN: that consists of the simple name, version, culture, and public key token. 
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. 
LOG: Appbase = file:///C:/Program Files/Autodesk/Revit 2014/ 
LOG: Initial PrivatePath = NULL 
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\Program Files\Autodesk\Revit 2014\Revit.exe.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. 
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/Xceed.Wpf.Toolkit.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/SDA/bin/Xceed.Wpf.Toolkit.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/SDA/bin/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.DLL. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/Xceed.Wpf.Toolkit.EXE. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.EXE. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/SDA/bin/Xceed.Wpf.Toolkit.EXE. 
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit 2014/SDA/bin/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.EXE. 

     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.Assembly.Load(AssemblyName assemblyRef) 
      at System.Windows.Baml2006.Baml2006SchemaContext.ResolveAssembly(BamlAssembly bamlAssembly) 
      at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlTypeToType(BamlType bamlType) 
      at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId) 
      at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId) 
      at System.Windows.Baml2006.Baml2006Reader.Process_ElementStart() 
      at System.Windows.Baml2006.Baml2006Reader.Process_OneBamlRecord() 
      at System.Windows.Baml2006.Baml2006Reader.Process_BamlRecords() 
      at System.Windows.Baml2006.Baml2006Reader.Read() 
      at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector) 
      at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
     InnerException: 

通常當我想從Revit中引用的第三方組件,插件,我只要確保第三方DLL被複制到相同的位置,我的插件DLL。我檢查並將Xceed.Wpf.Toolkit.dll複製到包含我的插件DLL的目錄中。

我從錯誤中的日誌消息中注意到它正在Revit程序目錄中尋找DLL。將Xceed.Wpf.Toolkit.dll複製到此目錄後,我不再收到錯誤。

但是,我有現有的插件部署工具,這些工具依賴於插件文件位於它們自己的獨立文件夾中。

那麼,有沒有人有任何想法如何讓我的插件找到WPF Toolkit庫?

+0

我不知道解決方案,但我用它在過去,並得到一些錯誤。我可以建議你1件事。右鍵單擊dll文件。轉到屬性並解除封鎖。我認爲這可能會有所幫助。 – Vishal

+0

我也面臨着同樣的問題.. :( –

回答

9

所以,我發現從2014年

今天我遇到了同樣的問題,以我的這個問題,一個新的,更好的解決方案,從裝載程序集的WPF控件將引發XamlParseException,只是這一次是用我創建的WPF控件庫程序集。

我試過DLL移動到同一文件夾中的EXE,並且在此之前解決了這個問題。

經過一番搜索,我發現了telerik.com論壇這樣一個問題: http://www.telerik.com/forums/xamlparseexception-could-not-load-file-or-assembly

事實證明,如果你只是給控制的名稱,通過添加x:Name屬性,這會引用添加到控制代碼隱藏並由於某種原因解決加載程序集時的問題。

<!--This causes a XamlParseException --> 
    <:MyCustomControl /> 

    <!-- This works --> 
    <mylib:MyCustomControl x:Name="foobar"/> 
+0

對於我(並使用Cefsharp),添加一個名稱並沒有添加對代碼隱藏的引用。你介意添加參考文件的樣子嗎? – Garrett

+1

@Garrett,我認爲這個想法是它被添加到你的代碼隱藏的自動生成部分。你應該可以在'obj'文件夾中找到它,比如'obj \ MainWindow.g.i.cs'。你的代碼是一個部分類,這也是,並且它們一起被串聯到一個整個類中。當使用'x:Name'時,我希望在該文件中出現一行。 –

0

System.Reflection命名空間中,有Assembly類。這可用於將新程序集加載到當前AppDomain中。

Assembly.LoadFrom("FileLocation"); 

儘管這仍然令人討厭,但我認爲這可能是讓它加載不在主目錄中的庫的唯一方法。

8

我很喜歡這種方法。 您可以在AppDomain上爲AssemblyResolve事件註冊一個事件,該事件捕獲程序集無法加載的時間。

它看起來像這樣:

// using System.Reflection and System.IO 

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); 

private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
{ 
    if (args.Name.ToUpper().StartsWith("XCEED.WPF")) 
    { 
     string asmLocation = Assembly.GetExecutingAssembly().Location; 

     string asmName = args.Name.Substring(0, args.Name.IndexOf(',')); 
     string filename = Path.Combine(asmLocation, asmName); 

     if (File.Exists(filename)) return Assembly.LoadFrom(filename); 
    } 
} 

你可以把它一點點比這更完整,但你的想法...

+0

感謝這個作品! –

1

雖然我個人認爲你應該做的陳述在接受的答案中(by @Matt),我想提一下,將dll複製到Autodesk Revit安裝中的「Program」文件夾中也可能會有效。如果我沒有記錯,他們還建議您將插件部署到此文件夾的子文件夾中,以確保它正常工作。我懷疑,這是由於你所擁有的效果。

+1

接受的解決方案爲屬性網格,但無法正常工作Avalon的碼頭。不過,我發現,你把所有的WPF工具包和Avalon的建議在Revit程序文件文件夾中的Dock DLLS工作正常,但是,這並不適用於我爲Revit插件開發的安裝過程。您知道爲什麼WPF Toolkit dll會出現這種情況?Usualy I'm能夠通過將DLL複製到與我的加載項DLL相同的位置來包含第三方庫。 –

+0

@EricAnastas,不,對不起,我現在不知道。 –

+0

將DLL添加到「Program」文件夾確實對我有用,但是將我的build文件夾複製到子文件夾中(我將其放入「AddIns」子文件夾中)不起作用。我發現DLL必須是'revit.exe'的兄弟。 你有沒有參考他們建議將插件部署爲子文件夾的位置? – Garrett

6

我知道這是一個非常古老的問題,但不久之前我偶然碰到了這個確切的錯誤。如果您的Visual Studio應用程序使用兩個項目或引用另一個項目的項目,我會檢查以確保兩個項目都安裝了擴展工具包。

右鍵單擊您的兩個項目,然後單擊「管理NuGet包」,然後在對話框的左側瀏覽至「已安裝的包」。如果您在兩個項目中都沒有看到擴展工具包,則可以使用該管理器在線搜索併爲您安裝。

我的問題是,我只在一個項目上安裝了擴展工具包。

希望這可以幫助別人在未來。

+0

您在查看例外情況時google已回覆,並且未讀完整個問題就回復。如果你花時間充分閱讀這個問題,你會明白我爲什麼投票。 – Pluc

5

雖然這可能已經解決了,一個常見的原因是失敗的Xceed.Wpf.Toolkit DLL添加到您的入口點的項目。您可能已將其添加到您的一個類庫文件項目中,並將其「Copy Local」屬性設置爲true。對此dll的引用也必須添加到包含App.xaml.cs並且其「Copy Local」屬性設置爲true的主項目中。

我很驚訝的Visual Studio 2013不會自動處理這個問題。

+0

謝謝......這讓我瘋狂,我無法弄清楚發生了什麼事。 – Jon

0

確保您「解鎖」了Xceed組件。右鍵單擊該文件並選擇屬性,然後選擇「取消阻止」。 VS將毫無錯誤地編譯代碼,但是當你運行時,Windows將不會加載程序集。我的礦井甚至合併成一個集合。

0

我使用Fody Costura來將Xceed.Wpf.Toolkit.dll嵌入到已編譯的.dll中。 只需使用NuGet安裝它並在您的Packet Manager Console中輸入Install-CleanReferencesTarget即可。

0

當控制從XAML,從您的Xceed.Wpf.Toolkit.dll加載調用程序集加載是PresentationFramework.dll。因此,在這種情況下,CLR不會查看您的加載項文件夾(從外掛的主程序集加載另一個類時它會執行什麼操作,因爲它會查找調用程序集的文件夾)。

所以,你可以像你找到的那樣,在代碼隱藏中提供一個對控件的引用,或者你可以使用AppDomain.CurrentDomain.AssemblyResolve來強制CLR查看你的插件文件夾。

把在Revit安裝文件夾中的dll的作品,但它在我的角度來看一個不好的做法,因爲它可以由其他插件的安裝與難以測量結果被覆蓋。

相關問題