17

別のアプリケーションである Autodesk Revit 用のアドインを開発しています。このアドインは、別個の DLL クラス ライブラリとして構築されています。WPF ウィンドウの 1 つでWpf Tool Kit プロパティ グリッドを使用しようとしています。プロパティ グリッドは 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: 

通常、Revit プラグインからサード パーティのアセンブリを参照する場合、サード パーティの DLL がプラグイン DLL と同じ場所にコピーされていることを確認します。チェックしXceed.Wpf.Toolkit.dllたところ、プラグイン DLL を含むディレクトリにコピーされています。

エラーのログ メッセージから、Revit プログラム ディレクトリで DLL を探していることがわかりました。このディレクトリにコピーXceed.Wpf.Toolkit.dllした後、エラーは表示されなくなりました。

ただし、独自の分離フォルダーにあるプラグイン ファイルに依存する既存のプラグイン展開ツールがあります。

それで、プラグインを入手してWPF Toolkitライブラリを見つける方法を知っている人はいますか?

4

10 に答える 10

11

私はこのアプローチのファンです。AssemblyResolve イベントの AppDomain にイベントを登録できます。これは、アセンブリを読み込めないときにキャッチされます。

次のようになります。

// 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);
    }
}

これよりももう少し完全にすることもできますが、アイデアはわかります...

于 2014-03-01T21:40:01.150 に答える
9

これは非常に古い質問であることは知っていますが、少し前にこの正確なエラーに出くわしました。Visual Studio アプリケーションが 2 つのプロジェクトを使用するか、別のプロジェクトを参照するプロジェクトを使用する場合、両方のプロジェクトに拡張ツールキットがインストールされていることを確認します。

両方のプロジェクトを右クリックして [NuGet パッケージの管理] をクリックし、ダイアログの左側で [インストール済みパッケージ] を参照します。両方のプロジェクトに拡張ツールキットが表示されない場合は、マネージャーを使用してオンラインで検索し、インストールすることができます。

私の問題は、両方ではなく 1 つのプロジェクトにのみ拡張ツールキットをインストールしていたことです。

うまくいけば、これは将来誰かを助けるでしょう。

于 2014-08-21T15:06:59.173 に答える
1

個人的には、受け入れられた回答(@Mattによる)に記載されているとおりに実行する必要があると考えていますが、DLLをAutodesk Revitインストールの「プログラム」フォルダにコピーすると、おそらくうまくいくことにも言及したいと思います。私の記憶が正しければ、アドインをこのフォルダーのサブフォルダーに展開して、確実に機能するようにすることも提案されています。それはあなたが持っているような影響によるものだと思います。

于 2014-03-03T08:30:41.800 に答える
0

System.Reflection名前空間には、Assemblyクラスがあります。これを使用して、新しいアセンブリを現在の AppDomain に読み込むことができます。

Assembly.LoadFrom("FileLocation");

これはまだ面倒ですが、これがメインディレクトリにないライブラリをロードさせる唯一の方法かもしれないと思います.

于 2014-03-01T04:54:45.787 に答える
0

Fody Costuraを使用Xceed.Wpf.Toolkit.dllして、コンパイル済みの にを埋め込みました.dll。NuGet を使用してインストールし、 に入力Install-CleanReferencesTargetするPacket Manager Consoleだけです。

于 2015-10-09T14:29:57.780 に答える