none
Windows Installer not registering C# COM DLL properly

    Question

  • I am having problems with Windows Installer registering my C# COM DLL. I have it set to register in Visual Studio 2010, so when I build, it works. When I install from Windows Installer, it doesn't register the full path of mscoree.dll. FYI, I can't find the information in the registry, I'm just going by what Excel says.

    I have a ComRegisterFunction like this:

     

    [ComRegisterFunction]
    public static void RegisterFunction(Type type)
    {
    	Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
    	RegistryKey key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), true);
    	key.SetValue("", System.Environment.SystemDirectory + @"\mscoree.dll", RegistryValueKind.String);
    }
    

    Visual Studio registers the full path, Windows Installer registers only "mscoree.dll", and Excel says it can't find mscoree.dll. The Windows Installer is set to register the output DLL as vsdrpCOM. I tried vsdrpCOMSelfReg, but I got an error when I tried to build. What am I doing wrong to not get the full path to mscoree.dll?

     

    EDIT:

    I'm not sure anymore if this is a COM registration issue. Symptoms: In the Excel 2007 Add-ins manager for Excel Add-ins, when my add-in is selected in the list Excel displays a message saying 'Cannot find add-in 'mscoree.dll'. Delete from this list?'. This could possibly be related to the fact that I have a VSTO add-in in the same project.

    • Edited by kendfrey Monday, November 21, 2011 1:36 PM
    Thursday, November 10, 2011 4:52 PM

Answers

  • I found the responsible registry key: HKCU\Software\Classes\Wow6432Node\CLSID\{myguid}\InprocServer32, in the default value. If I change it from 'mscoree.dll' to 'C:\Windows\System32\mscoree.dll' Excel does not complain anymore.
    • Marked as answer by kendfrey Monday, November 21, 2011 4:00 PM
    Monday, November 21, 2011 4:00 PM

All replies

  • A little update, I threw in a messagebox in my RegisterFunction, and it showed up when I built the project with VS, but not when I ran the installer.
    Thursday, November 10, 2011 6:09 PM
  • Windows Installer setup projects don't call the register function. Just mark thje properties of the Dll as a vsrd..COM choice to have it registered. That is the right thing to do. If you get an error, tell us what it is. It may be missing a dependent Dll or something.

    You should also us the Registry IDE to create those registry entries. The System folder can be described as [SystemFolder] and the location of your file will be based on the property of the folder where you installed it (such as [CommonFilesFolder]MyCompany\MyProduct\Nameof.dll

     


    Phil Wilson
    Thursday, November 10, 2011 6:34 PM
    Moderator
  • P.S. Don't be doing your testing on the same sysem where you're building it, that will just get confusing real fast.
    Phil Wilson
    Thursday, November 10, 2011 6:35 PM
    Moderator
  • My DLL is set to register vsdrpCOM. That doesn't work.
    Thursday, November 10, 2011 6:37 PM
  • The trouble is "that doesn't work" doesn't give anyone a clue about what might be going wrong. It *does* work because it's used all the time, so it's just something specific to your situation.
    Phil Wilson
    Thursday, November 10, 2011 9:55 PM
    Moderator
  • I was just making sure that you understood the information that you missed when reading the OP.

    If you ask for information, I would be happy to provide you with it, so that you can help me get this issue behind me. But if you tell me to do something that I said that I had done, it gets us nowhere but an argument. If you can help me, please let me know how I can help you help me.

    Thursday, November 10, 2011 10:03 PM
  • Excuse me, kendfrey, do you mean you want register the mscoree.dll which is belong to the .Net Framework? Are you using vs2005?

    Maybe you can have a read about this document: http://msdn.microsoft.com/en-us/library/ms173189(v=vs.80).aspx

    I think you can try to use the Register Editor in the Visual Studio Setup project to create the register path, instead of using codes.

    I think if you Visual Studio has this template to create office project, then it will be work for you:

    And if there's any error, please show us the completed information, and the screenshot, I'm not a office development expert, not ensure if my thinking is exactly what you got.

    If there's any concern, please feel free to let me know.

    Best wishes,

     


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, November 11, 2011 7:04 AM
    Moderator
  • I am not registering mscoree itself, but I need a reference to it, something to do with Excel loading it. It plain doesn't work without the fully qualified path, so its not just a little quirk. The page you linked to had some code, but that code skipped the mscoree part. The reason I don't want to use the Registry Editor is for simplicity and not hardcoding the values. I do use it for registering the VSTO add-in, but not COM registration.

    The issue here at hand is, why isn't Windows Installer running my registration code?

    Friday, November 11, 2011 1:01 PM
  • After a little research, it seems Windows Installer is taking a shortcut and not actually running regasm.exe. I think I will need to run regasm as a custom action, but I can't figure out how.
    Friday, November 11, 2011 3:38 PM
  • Ugh, I give up. I got regasm to run (by calling it with a JScript custom action, which was the best way I could come up with) but it didn't do what it was supposed to. It seems to work if I leave it how it was, but Excel wants to get rid of the addin because it cant find mscoree. I guess I will have to hope that it doesn't break. I am sick and tired of Microsoft.

    Occupy Microsoft!

    Friday, November 11, 2011 7:01 PM
  • When you use the registry IDE what hardcoding are you referring to? The folder values are property names, and they are just like your "System.Environment.SystemDirectory". Just say [SystemFolder]

    Windows Installer does not call COMRegisterFunction methods, that's just the way it works. It's not supposed to because they are purely a .NET regasm thing. If this is the thing that "doesn't work", the fact is that is not supposed to work because installers don't do that.

    Windows Installer does not need to run regasm at install time. Developers might do that but installers don't. When you choose vsrdxCOM, the build extracts the registration data at build time and stores it in the MSI file. When you do the install it copies the Dll to disk and writes the registry entries. It does it this way because it's fast, safe, and if the install fails it will also undo it.

    This as worked for years without needing to run regasm. I think you've just got stuck on the idea that regasm and COMRegisterFunction is the way this works during install, but it isn't.

    http://www.simple-talk.com/dotnet/visual-studio/build-and-deploy-a-.net-com-assembly/ 


    Phil Wilson
    Friday, November 11, 2011 7:50 PM
    Moderator
  • So, if it copies the registry data at build time, how come is it different than at build time? Specifically, the full path to mscoree is entered when I build, but not when I install.

    You asked what hardcoding I am referring to. The code makes use of a type's CLSID/GUID when registering. Doing it in the Registry Editor would mean hardcoding those. There better not be a Windows Installer property for anything of that nature.

    Friday, November 11, 2011 8:00 PM
  • kendfrey, can you help me to list out the steps what you will do to deploy your add-in to another computer manually?

    Since, I think only we can know what steps can let it work in another computer, then we can use the Visual Studio Setup project or others deployment technical to automate this proceed.


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Sunday, November 13, 2011 9:32 AM
    Moderator
  • I never have done it manually. Visual Studio does a fine job, and the idea is to replicate that in Windows Installer.

    However, since you asked there are two main ways of doing it.

    1:

    Copy the required files to the target machine.

    Register the addin DLL with COM.

    Use Excel to find the VSTO addin and install it.

    Use Excel to find the Automation addin and install it.

    2:

    Copy the required files to the target machine.

    Register the addin DLL with COM.

    Modify the registry to install the VSTO addin.

    Modify the registry to install the Automation addin.

    The bold line is where this issue lies.

    Monday, November 14, 2011 6:28 PM
  • Can you help me to clarify that, do you mean that the add-in can be registered to the end user system, and list at the Excel, but it will give you message that it cannot find the mscoree.dll? Or those are all failed, you have not registered the dll and let it list in the Excel yet? If so, then our goal is to register the dll in the end user system, let it can list out in the Excel firstly, then consider to test and research to let it run find on the end user Excel secondly, right?

    I recommend you to do those manually first to avoid some installer aspect problem, after you can deploy the addin to user system successfully, then we can be told that the project is passed the test, then we can use the Visual Studio Setup project to automate the deployment proceed according to our manually steps.

    After we subdivision the problem to questions, then we can put focus one by one to solve them easier, and do not need to assume too much scenarios.

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 15, 2011 6:25 AM
    Moderator
  • I am writing to check the status of the issue on your side. 
    What about this problem now? 
    Would you mind letting us know the result of the suggestions?

    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 7:44 AM
    Moderator
  • I still haven't found a 'real' solution. You are correct when you mention the message about not being able to find mscoree.dll. I haven't tried doing an installation manually, because that would be pretty complex and I don't know if I would miss something. Currently the status of this problem is "operable but brittle".
    Thursday, November 17, 2011 1:28 PM
  • I think you can see that if you have not do those test to exclude the probable causes, then it is hard to narrow down the problem, not to see find the real direction which will lead us to the real solution.
    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 3:29 PM
    Moderator
  • Can anyone give more information?
    Friday, November 18, 2011 4:38 PM
  • Excuse me, kendfrey, have you tested my suggestions?

    We want to help you, but we need you to help us test the suggestions, since we have no the same issue project in our side to research.

    I hope you can try them.

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 18, 2011 5:34 PM
    Moderator
  • I tested it by disabling COM registration in the installer, and running regasm on the dll after it was installed. It said it must be strong-named to register it with /codebase. Does this have anything to do with the full path problem? I wasn't sure what to make of it.
    Friday, November 18, 2011 8:04 PM
  • Yes, it needs the assembly signed(but it is only a warning, the result will be succeed), if you use the /codebase switch with the regasm tool.


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Saturday, November 19, 2011 7:11 AM
    Moderator
  • I noticed after running regasm, Excel didn't say the usual 'cant find 'mscoree.dll' ', instead it had 'cant find '' '. (empty string) So regasm didnt help this at all. What does Visual Studio do that gives the full path to mscoree.dll, but the installer doesn't? I'm beginning to wonder if this is actually not a registry issue. I did a few diffs on the registry, but I didn't find anything conclusive.
    Saturday, November 19, 2011 2:41 PM
  • ->cant find ''

    Does it mean that you got this message when you check it form your Excel? If so, then it can be ensured that the addin registered succeed, I think maybe there's something wrong in the method logic, there's anything wrong or exceptions form your codes.

    You can open your Excel, and then open the Excel Options Window:

    Then you can put the focus on analysis the codes, I think.

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Saturday, November 19, 2011 3:32 PM
    Moderator
  • It shows up when I go into Office Button>Excel Options>Add-ins>Excel Add-ins>Go, but when I click it in the list, I get the message 'Cannot find add-in ''. Delete from this list?'. If I set the installer to register automatically, the message says 'Cannot find add-in 'mscoree.dll'. Delete from this list?'. If I build the project with VS and then run Excel, it doesn't display a message.

    This is not an error in my code. I'm not sure where the difference is.


    • Edited by kendfrey Monday, November 21, 2011 1:37 PM
    Saturday, November 19, 2011 4:49 PM
  • Please try my demo:

    1. Create a Class Library project.

    2. 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using Microsoft.Win32;
    
    //ReBuild
    //regasm /codebase ClassLibrary2.dll
    //regasm /u /codebase ClassLibrary2.dll
    namespace ClassLibrary2
    {
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ComVisible(true)]
        public class Class1
        {
            public int MySumFunc(int a, int b)
            {
                return a + b;
            }
    
            [ComRegisterFunction]
            public static void RegisterFunction(Type type)
            {
                Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
                RegistryKey key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), true);
                key.SetValue("", Environment.SystemDirectory + @"\mscoree.dll", RegistryValueKind.String);
            }
    
            [ComUnregisterFunction]
            public static void UnregisterFunction(Type type)
            {
                Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"), false);
            }
    
            private static string GetSubKeyName(Type type, string subKeyName)
            {
                StringBuilder s = new System.Text.StringBuilder();
                s.Append(@"CLSID\{");
                s.Append(type.GUID.ToString().ToUpper());
                s.Append(@"}\");
                s.Append(subKeyName);
                return s.ToString();
            }
        }
    }
    
    

     

    3. ReBuild the project, and "regasm /codebase ClassLibrary2.dll"

    4.

    option1

    5.

    option2

    6.

    option3

    7.

    option4

    8.

    result

    9.

    result2

     


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Sunday, November 20, 2011 9:17 AM
    Moderator
  • I think you are treating a simple problem with too much emphasis on the wrong thing. But I will try your idea if I have time.
    Monday, November 21, 2011 1:30 PM
  • I found the responsible registry key: HKCU\Software\Classes\Wow6432Node\CLSID\{myguid}\InprocServer32, in the default value. If I change it from 'mscoree.dll' to 'C:\Windows\System32\mscoree.dll' Excel does not complain anymore.
    • Marked as answer by kendfrey Monday, November 21, 2011 4:00 PM
    Monday, November 21, 2011 4:00 PM
  • I can't get Windows Installer to register the full path to mscoree.dll in HKCU\Software\Classes\Wow6432Node\CLSID\{myguid}\InprocServer32. Can I somehow get it to copy the value across? VS fills in the full path, but Windows Installer won't without hardcoding the key (including the type GUID).
    Monday, November 21, 2011 6:49 PM
  • Do you mean after you did this:

    --> key.SetValue("", System.Environment.SystemDirectory + @"\mscoree.dll", RegistryValueKind.String);

    It also just give you a mscoree.dll instead of the C:\Windows\System32\mscoree.dll?

    If so, then I'm afraid we will need to use the Registry Editor to fill the full path at development time.

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 22, 2011 2:56 AM
    Moderator
  • I am writing to check the status of the issue on your side. 
    What about this problem now? 
    Would you mind letting us know the result of the suggestions?

    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 24, 2011 8:56 AM
    Moderator
  • I have figured out which registry key needs to be set to what value, but I haven't figured out how to make Windows Installer set it. Please leave comments regarding this in http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/a88703d0-8213-4c77-91ed-490fd9782c67/.
    Thursday, November 24, 2011 1:42 PM
  • I'm in that discussion, and give out my thinking to help you, have you tried the suggestion provided in the last post in that thread?

     


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 25, 2011 2:32 AM
    Moderator
  • Yes, I did, but I am waiting to see if Phil Wilson can provide more information regarding his suggestion, as it may be better if it can be automated.
    Friday, November 25, 2011 1:28 PM
  • In fact, I have doubt about that.

    Since if you do not use the Registry Editor to input the mscoree.dll, then I have no idea how the "mscoree.dll" will in msi.

    I think it is said that you will need to use Registry Editor, if you can use the Registry Editor, then I think my suggestion will give you the same result.

     


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 25, 2011 1:48 PM
    Moderator
  • Please leave your comments regarding the other question in the other thread. I am removing my alert for this thread.
    Friday, November 25, 2011 1:51 PM
  • OK,

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 25, 2011 2:07 PM
    Moderator