0

I am creating a IconHandler shell extension in c# using SharpShell. Here is the code for my dll.

using SharpShell.Attributes;
using SharpShell.SharpIconHandler;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DllIconHandler
{
    [ComVisible(true)]
    [COMServerAssocation(AssociationType.ClassOfExtension, ".jxe")]
    public class DllIconHandler : SharpIconHandler
    {
        protected override Icon GetIcon(bool smallIcon, uint iconSize)
        {
            Icon icon = null;
            FileInfo file = new FileInfo(SelectedItemPath);
            long size = file.Length;

            if (size > 0)
            {
                icon = new Icon("C:\\Users\\Owner\\Desktop\\icon1.ico");
            }
            else
            {
                icon = new Icon("C:\\Users\\Owner\\Desktop\\icon2.ico");
            }

            return GetIconSpecificSize(icon, new Size((int)iconSize, (int)iconSize));
        }
    }
}

I built this into a dll and moved the dll onto my desktop. Then i ran regasm on the dll using the following commands in the command prompt as an administrator.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe C:\Users\Owner\Desktop\DllIconHandler.dll /codebase

But when i do this an error appears

RegAsm : error RA0000 : An error occurred inside the user defined Register/Unreg
ister functions: System.InvalidOperationException: Cannot open default icon key
for class jxe_auto_file
   at SharpShell.ServerRegistration.ServerRegistrationManager.SetIconHandlerDefa
ultIcon(RegistryKey classesKey, String className)
   at SharpShell.ServerRegistration.ServerRegistrationManager.RegisterServerAsso
ciations(Guid serverClsid, ServerType serverType, String serverName, Association
Type associationType, IEnumerable`1 associations, RegistrationType registrationT
ype)
   at SharpShell.SharpShellServer.DoRegister(Type type, RegistrationType registr
ationType)

It appears that something is wrong in the registry.

Popgalop
  • 737
  • 2
  • 9
  • 26
  • It fails when trying to open a registry key. Error reporting tends to be so-so in libraries like this, it isn't very clear why it didn't report an error when creating the key. Maybe you are supposed to create the file association yourself before trying to register the component. Do make sure you run Regasm from an elevated command prompt. – Hans Passant Sep 02 '13 at 14:19
  • i ran it using run as administrator – Popgalop Sep 02 '13 at 14:20
  • Well, you got the source code so you can just debug it. Start VS elevated, Project + Properties, Debug tab. Start external program and type your Regasm.exe command line. Set a breakpoint on DoRegister(). – Hans Passant Sep 02 '13 at 14:26
  • but i dont have the souurce for DoRegister() – Popgalop Sep 02 '13 at 14:30
  • Of course you do, SharpShell is an open source project. – Hans Passant Sep 02 '13 at 14:31
  • why the same problem will still occur and i will still have the same information – Popgalop Sep 02 '13 at 22:54

1 Answers1

0

The entry in your registry should looks like this:

HKEY_CLASSES_ROOT
jxe_auto_file
DefaultIcon: (Default) (Path to icon)

I'm pretty sure there was no "DefaultIcon" in your jxe_auto_file entry

Eledra Nguyen
  • 400
  • 1
  • 12