无法加载文件或程序集'Xceed.Wpf.Toolkit

Eri*_*tas 15 c# wpf wpftoolkit revit revit-api

我正在为另一个应用程序Autodesk Revit开发一个加载项,它是作为一个单独的DLL类库构建的.我正在尝试在我的一个WPF窗口中使用Wpf工具包属性网格.属性网格在Visual Studio中显示正常,而intellisense也可以.但是当我尝试使用加载项加载启动Revit时,我得到以下异常.

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: 
Run Code Online (Sandbox Code Playgroud)

通常,当我想从Revit插件引用第三方程序集时,我只需确保将第三方DLL复制到与插件DLL相同的位置.我检查并Xceed.Wpf.Toolkit.dll正在复制到包含我的插件DLL的目录.

我从错误中的日志消息中注意到它正在Revit程序目录中查找DLL.复制Xceed.Wpf.Toolkit.dll到此目录后,我不再收到错误.

但是,我有现有的插件部署工具,这些工具依赖于插件文件位于他们自己的隔离文件夹中.

那么,有没有人知道如何让插件找到WPF工具包库?

Eri*_*tas 20

所以,我从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 -->
  <mylib:MyCustomControl />

  <!-- This works -->
  <mylib:MyCustomControl x:Name="foobar"/>
Run Code Online (Sandbox Code Playgroud)


Mat*_*att 9

我是这种方法的粉丝.您可以在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);
    }
}
Run Code Online (Sandbox Code Playgroud)

你可以让它比这更完整,但你明白了......


Joh*_*ust 7

我知道这是一个非常古老的问题,但我不久前遇到了这个确切的错误.如果您的visual studio应用程序使用两个项目或引用另一个项目的项目,我会检查以确保BOTH项目安装了扩展工具包.

右键单击两个项目,然后单击"管理NuGet包",然后在对话框的左侧浏览"已安装的包".如果您在两个项目中都没有看到扩展工具包,那么您可以使用管理器在线搜索并为您安装它们.

我的问题是我只在一个项目上安装了扩展工具包而不是两个.

希望这有助于将来的某个人.


Kla*_*Nji 7

虽然这可能已经解决,但常见的原因是未能将Xceed.Wpf.Toolkit dll添加到入口点项目中.您可能已将其添加到您的一个类库项目中,并将其"复制本地"属性设置为true.此dll的引用也必须添加到主项目中,该项目包含App.xaml.cs,其"Copy Local"属性设置为true.

我很惊讶Visual Studio 2013不会自动处理这个问题.