locked
Can't add a typelib(x64) to a C# project as project-reference on a 32bit build machine. RRS feed

  • Question

  • Dears,

      I have a C# dll(built as "Any CPU") relying on some COM-Dll(64bit).
      But when I try to add the typelib from that COM-Dll to my C# project to resolve project-reference on a 32bit build machine, I get an error message:

        "A reference to <path to my typelib> could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

      The COM-Dll(64bit) can be successfully registered on a 64bit platform. Therefore, it should be a valid COM component, of course.

      I know it's impossible to register a 64bit Dll on a 32bit platform. But Typelib should only be used to provide type-information during compile-time.
      It should not matter if the build machine is 32bit or 64bit.

      Is there any good reason why I can't add that typelib to my C# project ?
      Furthermore, it there any good way to resolve this issue ?

      Below is my environment:
        ////////////////////////////////////////
        OS: XP Pro SP3. (32bit)
        Building Environment: VS2005 Pro
        .NET framework: 2.0
        ////////////////////////////////////////

      Any suggestion or advice is welcome.

    B.R.
    Mission.
    Tuesday, February 9, 2010 10:39 AM

Answers

  • You are incorrect in assuming that a typelib should be readable irrelevant of bitness.  This is incorrect.  The typelib information is stored as a resource in the binary.  In order to get to it the binary has to be loaded (via LoadTypeLibEx) and this won't work if you're trying to load an x64 binary on an x86 OS.  Thus you cannot do anything with a COM object that is x64 on an x86 OS.  You can, of course, go the other way (ignoring standard issues with loading x86 COM objects in an x64 process).

    Michael Taylor - 2/10/2010
    http://msmvps.com/blogs/p3net
    • Marked as answer by Mission Liao Thursday, February 11, 2010 3:16 AM
    Wednesday, February 10, 2010 6:41 PM
    Moderator

All replies

  • Set project target from 'Any CPU' to 'x64'. Does that help?

    -Karel
    Wednesday, February 10, 2010 4:49 PM
  • You are incorrect in assuming that a typelib should be readable irrelevant of bitness.  This is incorrect.  The typelib information is stored as a resource in the binary.  In order to get to it the binary has to be loaded (via LoadTypeLibEx) and this won't work if you're trying to load an x64 binary on an x86 OS.  Thus you cannot do anything with a COM object that is x64 on an x86 OS.  You can, of course, go the other way (ignoring standard issues with loading x86 COM objects in an x64 process).

    Michael Taylor - 2/10/2010
    http://msmvps.com/blogs/p3net
    • Marked as answer by Mission Liao Thursday, February 11, 2010 3:16 AM
    Wednesday, February 10, 2010 6:41 PM
    Moderator
  • Hi Tailor,

       Thanks for your reply, it seems that I make a really big mistake.

    B.R.
    Mission.
    Thursday, February 11, 2010 3:47 AM
  • Hi Karel,

       Thanks for your suggestion, I've considered if this way could resolve my problem.
       But I know it's not suggested to use configuration other than "Any CPU" for DLL. I don't way to leave another RD into similar ____ later.

    B.R.
    Mission.
    Thursday, February 11, 2010 3:48 AM
  • If your app depends on x64 COM DLL, then it doesn't make sense to have it "Any CPU". You are already bound only to x64 platform.

    -Karel
    Thursday, February 11, 2010 5:05 PM
  • You are incorrect in assuming that a typelib should be readable irrelevant of bitness. This is incorrect. The typelib information is stored as a resource in the binary. In order to get to it the binary has to be loaded (via LoadTypeLibEx) and this won't work if you're trying to load an x64 binary on an x86 OS. Thus you cannot do anything with a COM object that is x64 on an x86 OS. You can, of course, go the other way (ignoring standard issues with loading x86 COM objects in an x64 process).

    Michael Taylor - 2/10/2010
    http://msmvps.com/blogs/p3net

    Thanks for your effort! It's quite useful.
    Saturday, February 12, 2011 1:02 AM