Installing a SharpShell-ShellExtension via srm.exe fails with “Cannot cast the underlying exported value”

May 15, 2015 at 6:20 AM
Hi,

I'm trying to install a Sharpshell-ShellExtension using srm.exe. Testing the extension in SharpShell ServerManager works. It can also install it there.

My Problem occurs when I'm using srm.exe to install it. I get exactly the same error messgae as here: http://stackoverflow.com/questions/25440626/srm-exe-install-shell-extension-fails-with-cannot-cast-the-underlying-exported
========================================
SharpShell - Server Registration Manager
========================================


Unhandled Exception: System.ComponentModel.Composition.CompositionContractMismatchException: Cannot cast the underlying exported value of type 'SharpShell.SharpShellServer (ContractName="SharpShell.ISharpShellServer")' to type 'SharpShell.ISharpShellServer'.
   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)
I already checked where I was runing srm.exe from, so this shouldnt be the problem.

It might be the Problem Simon Mourier mentioned in his comment, but honestly I dont know how I can check/fix this.

I shortended my Code to make it more readable:
using SP = Microsoft.SharePoint.Client;
using System.Collections.Generic;
using System.Windows.Forms;
using System;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.Win32;
using System.Security;
using System.Net;
using System.IO;

namespace SharpShell.SharpContextMenu
{

    /// <summary>
    /// The SharePoint Context Menu Extension
    /// </summary>
    public class Somethings : SharpContextMenu
    {


        protected override bool CanShowMenu()
        {
            return true;
        }

        protected override ContextMenuStrip CreateMenu()
        {
            //  Create the menu strip.
            var menu = new ContextMenuStrip();

            //  Create a 'count lines' item.
            var itemSomething = new ToolStripMenuItem
            {
                Text = "Do Something"
            };

            //  When we click, we'll call the 'Something' function.
            itemSomething.Click += (sender, args) => something();

            //  Add the item to the context menu.
            menu.Items.Add(itemSomething);

            //  Return the menu.
            return menu;
        }



        private void something()
        {

            MessageBox.Show("Do Something");
        }



    }
}
I need the usings because of some functions I cut for this example.
May 15, 2015 at 9:49 AM
I found the solution.

It seems that I used a old version of srm. exe. using the most recent one work.