none
Problem with com interop "Compile Error: User defined type not defined" RRS feed

  • Question

  • I have a .NET Class Library that I want to call from Excel. This worked great previously , but after cleaning up some code
    and changing name of project and namespace it stopped working. From an excel workbook I have created a reference to the typelibrary (tlb-file) called XLReportsLib

    Then I have some code in VBA to instansiate a class called "distributor", but I when trying to run the code there's an error.

    Public Sub Test()

    Dim l As XLReportsLib.Distributor
    Set l = New XLReportsLib.Distributor 'Generates error "Compile Error: User defined type not defined"
    End Sub

    To narrow the problem down,the Class library XLReportsLib has currently only one class (Distributor) and that class has a single method! Still I get this
    ugly error slammed in my face.


    If a create a new classLibrary from scratch and add this to my project, I can without problem call the new classlibrary and its classes/methods.
    So there must be something wrong/corrupt with my class library XLReportsLib. I have compared the two class libraries' (the working and the no working)
    properties and I can't find a single difference.

    Is this maybe a COM-problem/GUID issue? Any help appreciated.

    I use Visual Studio 2010/Office 2010 32bit on Windows / 64 bit.

    I have restarted Visual Studio, rebooted the computer, cleaned the solution without any success. I have tried using regasm.exe as an alternative to the "Register for COM interop" in VS.NET.

    It might be possible to move all the code files to a new project, but I still want to know why this does not work.

    Wednesday, April 3, 2013 8:32 PM

Answers

  • Hi Lellex,

    Thank you for posting on this forum.

    >>changing name of project and namespace it stopped working. 

    I think this is the root cause.

    You need to check all related namespaces have been changed. For example, when you changed the .vb files, but you may forget the .designer.vb, when you change the all form source files, you may forget the class file.

    >>Compile Error: User defined type not defined

     You can check the User defined type's namespace, is it in the same namespace with your current code?

    If you specially put them in different namespace, please make sure you have import the referenced namespace at the top of the current source file.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lellex Thursday, April 4, 2013 10:02 PM
    Thursday, April 4, 2013 6:18 AM
    Moderator

All replies

  • It seems like the class/functions you are accessing are not PUBLIC.  Only public objects excel will be able to extract from the library file.

    jdweng

    Wednesday, April 3, 2013 9:35 PM
  • Thanks, but the class is definitely public!
    Wednesday, April 3, 2013 9:59 PM
  • Are you compiling in x86 compatible mode?

    jdweng

    Wednesday, April 3, 2013 10:01 PM
  • Hi Lellex,

    Thank you for posting on this forum.

    >>changing name of project and namespace it stopped working. 

    I think this is the root cause.

    You need to check all related namespaces have been changed. For example, when you changed the .vb files, but you may forget the .designer.vb, when you change the all form source files, you may forget the class file.

    >>Compile Error: User defined type not defined

     You can check the User defined type's namespace, is it in the same namespace with your current code?

    If you specially put them in different namespace, please make sure you have import the referenced namespace at the top of the current source file.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lellex Thursday, April 4, 2013 10:02 PM
    Thursday, April 4, 2013 6:18 AM
    Moderator
  • Thanks Mike, you got me on the right track. Since I excluded all classes but one and stripped away all methods, there was no designer.vb. But you inspired me to open the project file in a a text editor and there I found a reference to the old project name. So after changing the node value to the new project name, everything started working directly!
    Thursday, April 4, 2013 10:02 PM