The server does not have a [PreviewHandler] attribute set.

Aug 14, 2015 at 2:41 PM
I'm trying to build and run the IconPreviewHandler sample provided in SharpShell. It builds fine, but when I test it in ServerManager.exe (2.2.0 via NuGet), it crashes in a variety of ways. I followed the instructions at http://www.codeproject.com/Articles/533948/NET-Shell-Extensions-Shell-Preview-Handlers because the documentation at https://github.com/dwmkerr/sharpshell#preview-handlers simply refers to the CodeProject article, and the documentation at https://sharpshell.codeplex.com/documentation is even more scant.

Please advise me on how to get the sample to work.

Here's the steps to reproduce the problem.

1) Downloaded the source, opened Visual Studio 2015, opened the project at ...\SharpShell\Samples\PreviewHandler\IconPreviewHandler.

2) Used NuGet to add SharpShell and SharpShellTools (version 2.2.0)

3) Build (which it does so cleanly).

4) Run ServerManager.exe (...\PreviewHandler\IconPreviewHandler\packages\SharpShellTools.2.2.0.0\lib).

5) Click on "File | Load Server". The file seems to load, but in the right-hand pane, the server is "Not Installed" nor "Not Registered" for either 32-bits or 64-bits.

Image

6) As per instructions in "Debugging the Shell Extension", I clicked on "Test Server in Test Shell", it doesn't highlight any ".ico" files, and when I click on an ICO file, it fails:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {A643C50D-4206-4121-A895-9EA5C919557A} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at ServerManager.TestShell.ShellPreviewHost.SetPreviewHandler(Guid previewHandlerGuid) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\Tools\ServerManager\TestShell\ShellPreviewHost.cs:line 27
at ServerManager.TestShell.TestShellForm.shellListView_SelectedIndexChanged(Object sender, EventArgs e) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\Tools\ServerManager\TestShell\TestShellForm.cs:line 241
at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

4) Assuming the instructions are incorrect, in ServerManager.exe, I click on "Server | Install Server (x64)", which now updates the RHS pane.

Image

7) Repeating, I clicked on "Test Server in Test Shell" in ServerManager.exe, with it crashing with same call stack as on step 3.

8) In ServerManager.exe, I click on "Server | Register Server (x64)". It now fails with:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> SharpShell.Exceptions.ServerRegistrationException: The server does not have a [PreviewHandler] attribute set.
at SharpShell.SharpPreviewHandler.PreviewHandlerRegistrar.Register(Type serverType, RegistrationType registrationType) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\SharpShell\SharpPreviewHandler\PreviewHandlerRegistrar.cs:line 25
at SharpShell.SharpPreviewHandler.SharpPreviewHandler.CustomRegisterFunction(Type serverType, RegistrationType registrationType) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\SharpShell\SharpPreviewHandler\SharpPreviewHandler.cs:line 541
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at SharpShell.Attributes.CustomRegisterFunctionAttribute.ExecuteIfExists(Type type, RegistrationType registrationType) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\SharpShell\Attributes\CustomRegisterFunctionAttribute.cs:line 27
at SharpShell.SharpShellServer.DoRegister(Type type, RegistrationType registrationType) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\SharpShell\SharpShellServer.cs:line 81
at SharpShell.ServerRegistration.ServerRegistrationManager.RegisterServer(ISharpShellServer server, RegistrationType registrationType) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\SharpShell\ServerRegistration\ServerRegistrationManager.cs:line 125
at ServerManager.ServerManagerForm.registerServerx64ToolStripMenuItem_Click(Object sender, EventArgs e) in c:\Repositories\GitHub\dwmkerr\sharpshell\SharpShell\Tools\ServerManager\ServerManagerForm.cs:line 315
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Aug 14, 2015 at 7:28 PM
Looks like a version skew on my end. First, I re-downloaded the source, making sure to grab the 2.2.0 branch, since that is what NuGet grabs in Visual Studio. Then, in ServerManager.exe, select "Server | Install Server (x86)", followed by "Server | Register Server (x86)", then "Test Server in Test Shell", it works. It still does not seem to work for x64 install/register, but that's probably not a problem for me.