2

SharpShell を使用して、この単純なシェル拡張機能 (エクスプローラーのコンテキスト メニュー) を作成しました。

[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
public class SampleExtension : SharpContextMenu
{
    protected override bool CanShowMenu()
    {
        return true;
    }
    protected override ContextMenuStrip CreateMenu()
    {
        var menu = new ContextMenuStrip();
        var item = new ToolStripMenuItem
        {
            Text = "Hello world!"
        };
        menu.Items.Add(item);
        return menu;
    }
}

SharpShell Server Manager を使用してデバッグで動作しますが、srm.exeコマンド ラインでインストールしようとすると、次のようになります。

srm.exe install ..\SampleExtension\bin\Debug\CountLinesExtension.dll -codebase  

System.ComponentModel.Composition.CompositionContractMismatchException was unhandled
  HResult=-2146233088
  Message=Cannot cast the underlying exported value of type 'SharpShell.SharpShellServer (ContractName="SharpShell.ISharpShellServer")' to type 'SharpShell.ISharpShellServer'.
  Source=System.ComponentModel.Composition
  StackTrace:
       at System.ComponentModel.Composition.ExportServices.CastExportedValue[T](ICompositionElement element, Object exportedValue)
       at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export)
       at System.ComponentModel.Composition.ExportServices.<>c__DisplayClassa`1.<CreateStronglyTypedLazyOfT>b__7()
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at ServerRegistrationManager.Application.<LoadServerTypes>b__2(Lazy`1 st)
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at ServerRegistrationManager.Application.InstallServer(String path, RegistrationType registrationType, Boolean codeBase)
       at ServerRegistrationManager.Application.Run(String[] args)
       at ServerRegistrationManager.Program.Main(String[] args)

これを修正する方法は?

4

1 に答える 1

3

同じ問題に遭遇しました。dll と同じディレクトリから srm.exe を実行していないことがわかりました。私たちのdllには他のdllが含まれていたため、そのようにロードできませんでした。すべて同じディレクトリにある dll を使用して srm.exe を実行すると、機能しました。

于 2014-12-19T22:44:04.963 に答える