COM DLL no longer working with excel

SilverShaded

Well-known member
Joined
Mar 7, 2020
Messages
93
Programming Experience
10+
My COM DLLs are not longer working from excel. (as far as i can tell its after installing .Net5 or .Net6 preview). The DLL is still created using .Net 4.8. The same code is working on a diferent VM.

The DLL is recognised by excel and so are the functions defined int he DLL. Howvere the code will not execute, the VBA just stops when it reached the call to the DLL fucntion.

Register COMinterop is set to true

Heres an Exacmple Code;

C#:
using System;
using System.Runtime.InteropServices;

namespace TestCOM
{
    [Guid("A3E6B57A-E794-439B-AE96-ADED4D89F991")]
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Class1
    {
        public double test()
        {
            return 999;
        }
    }
}

Code:
Dim test1 As New TestCOM.Class1

Function test2() As Double

test2 = test1.test()

End Function
 
Solution
Thanks for the quick reply, you were bang on with the first point. The VM was set up recently and i must have installed 64 bit excel by default (normally we use 32 bit), compiling the DLL with AnyCPU doesnt work but but 64 bit does!

Your last point about COM DLL in .Net 5 is my next target but from what ive read it's not as straightforward, if i can figure that out i can move my whole project to .Net5.

Excellent thanks!
It could be one of multiple things:
  • Bit widths do not match. 32-bit Excel trying to load 64-bit COM DLL, or 64-bit Excel trying to load 32-bit COM DLL.
  • Excel has already loaded a versions of the .NET Framework that is not compatible with the framework being used by the COM DLL. Excel may have already loaded a COM DLL that uses .NET Framework 4.8, and so it can't load another COM DLL that uses .NET 5.
  • COM DLLs in .NET 5 may not be fully supported -- may need to check the readme's and blogs. I've personally not kept up on that aspect of using .NET 5.
 
Thanks for the quick reply, you were bang on with the first point. The VM was set up recently and i must have installed 64 bit excel by default (normally we use 32 bit), compiling the DLL with AnyCPU doesnt work but but 64 bit does!

Your last point about COM DLL in .Net 5 is my next target but from what ive read it's not as straightforward, if i can figure that out i can move my whole project to .Net5.

Excellent thanks!
 
Solution
Back
Top Bottom