P
P
Pychev Anatoly2020-08-23 23:35:01
C++ / C#
Pychev Anatoly, 2020-08-23 23:35:01

How to run C# DLL library under office for x86 and x64?

Hello
I'm trying to build and run Dll for Office (for Excel in particular). The library is written in C#.
Collected an example on this lesson
So.
In VisualStudio 2019, a project was created using the "NET.Framework Class Library" template.
In Preferences checkbox is checked for "Make assembly visible to COM", Target NET 3.5 workbench

Working class code
using System.Runtime.InteropServices;

namespace howto_dll_for_excel
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class CSharpTools
    {
        [ComVisible(true)]
        public string AddBrackets(string value)
        {
            return "[" + value + "]";
        }
    }
}

Compilation proceeds without error
After compilation I register the dll library using
C:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe
and keys /tlb /codebase

As a result, everything works fine under excel 2007 x32. Under excel 2010 x64 and 2013 x64 does not work and gives an error Класс не зарегистрирован

Even if you register the library under
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe
the error remains relevant

An attempt to recompile the project under NET.Framework 4.7 also failed.

Tell me how to run the library under x64

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pfemidi, 2020-08-24
@pfemidi

Probably it is necessary to compile the library under x64.

N
none7, 2020-08-24
@none7

I had outdated information. So, I lied in the comment. The Regasm that you are using is 32-bit and all of its entries are in WOW64, including entries in the registry. Use the x64 build console to have regasm write to the correct registry branch. To correctly install the library you will need to call 2 different regasm!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question