Regasm没有在DLL上工作

时间:2013-09-02 13:43:44

标签: c# dll registry shell-extensions regasm

我正在使用SharpShell在c#中创建一个IconHandler shell扩展。这是我的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));
        }
    }
}

我将它构建成一个dll并将dll移动到我的桌面上。然后我在管理员命令提示符中使用以下命令在dll上运行regasm。

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

但是当我这样做时会出现错误

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)

注册表中似乎出现了问题。

1 个答案:

答案 0 :(得分:0)

注册表中的条目应如下所示:

HKEY_CLASSES_ROOT
jxe_auto_file
DefaultIcon :(默认)(图标路径)

我很确定你的jxe_auto_file条目中没有“DefaultIcon”

相关问题