error in HostItemProvider::GetHostobject

Last post 02-12-2007, 5:41 PM by Gary. 7 replies.
Sort Posts: Previous Next
  •  02-06-2007, 4:03 AM 254

    error in HostItemProvider::GetHostobject

    hi,

    I am doing VSTA integration job to my app.

    I did all tasks in integration manual. I can open the VSTA IDE in my app.

    but when I try to load a add-in made by VSTA project , error occurs in GetHostObject method.

    add-in is very simple. It's function is just displaying one message box in application startup.

    I don't think that add-in is wrong.

    error message is  :

    ==========================================================

    A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.VisualStudio.Tools.Applications.InteropAdapter.dll

    Additional information: The method or operation is not implemented.

    ==========================================================

    and this error occurs at red line.

    ==========================================================

    RemoteObjectContract^ HostItemProvider::GetHostObject(String^ primaryType, String^ primaryCookie)
     {
      if (String::Equals(primaryType, "geoCreator.Application", StringComparison::Ordinal))
      {
       IDispatch *pDisp = (IDispatch *)m_pApp;

       comAdapter = gcnew ComObjectAdapter((IDispatch *)pDisp,this->TypeInfrastructureManager);

       ...

    ==========================================================

    pDisp and this->TypeInfrastructureManager have normal value.

    what the error message means? and what should I do?

    please help me.


    yo man
  •  02-06-2007, 6:49 PM 257 in reply to 254

    Re: error in HostItemProvider::GetHostobject

    Hello Hyun,

    Have you implemented IDispatch::GetTypeInfo() and are you returning from it successfully?  Notice that the ShapeApp sample implements type information, which is required.

    You may be able to and work around the problem by simplifying your proxy layer -- by setting isExcluded=”true” for most of your object model in descriptor.xml.  that you have generated with proxygen:

    C:\>proxygen /l:"path to your library or .exe" /c:proxy.cs /o:descriptor.xml /f

    I recommend that you download and look at our testcon sample as an example of doing an integration using VAO.

    http://www.summsoft.com/files/folders/vsta_samples/entry248.aspx (test con sample)

    VAO simplifies the integration process considerably.

    VSTA Access Objects (VAO) Source useful for either managed or unmanaged COM application integrations.

     

    Regards,

    Gary Depue

  •  02-07-2007, 7:30 AM 258 in reply to 257

    Re: error in HostItemProvider::GetHostobject

    Thank you for your answer. Gary

    I want to know what "implemented IDispatch::GetTypeInfo() " exactly means.

    exactly which part of ShapeApp?

    because my VBA macro runs correctly, I don't think IDispatch implementation is wrong.

    ( Is more implementation needed to integrate VSTA with VBA app ? )

     

    more detailed error message is :

    Additional information: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented.

    Server stack trace:
       at Microsoft.VisualStudio.Tools.Applications.ComTypeAdapter.GetTypeAdapter(IDispatch* pDisp, Boolean isByRef, Boolean isArray, TypeInfrastructureManager typeInfrastructureManager)
       at Microsoft.VisualStudio.Tools.Applications.ComObjectAdapter.Initialize(IDispatch* pObject)
       at Microsoft.VisualStudio.Tools.Applications.ComObjectAdapter..ctor(IDispatch* pObject, TypeInfrastructureManager typeInfrastructureManager)
       at geoCreator.Integration.HostItemProvider.GetHostObject(String primaryType, String primaryCookie) in d:\companywork\개발관련\exercise\opengl_mfc_things\geocreator\vstahookup\hostitemprovider.cpp:line 27
       at Microsoft.VisualStudio.Tools.Applications.Internal.ExceptionManager.GetHostObject(String primaryType, String primaryCookie)
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

    ===================================================================

    I can't know what happens in Microsoft.VisualStudio.Tools.Applications.ComTypeAdapter.GetTypeAdapter.

    and I changed setting isExcluded=”true” for most of my object model in descriptor.xml.

    but I can't find any reason of my error.

    ( I modified descriptor.xml => only Application object 's isExcluded = "false" . but error still occurs )

    do you have any other advice?

    I can't find difference between ShapeApp and my app... ㅠ.ㅠ


    yo man
  •  02-07-2007, 12:31 PM 260 in reply to 258

    Re: error in HostItemProvider::GetHostobject

    Hyun,

    What programming language is your application written in? 

    >>I want to know what "implemented IDispatch::GetTypeInfo() " exactly means.

    >>exactly which part of ShapeApp?

    In the SHapeAppMFC app, ShapeAppMFCApp.h, the definition of class CShapeAppMFCApp includes:    DECLARE_OLETYPELIB(CShapeAppMFCApp)\

    And ShapeAppMFC.cpp includes:

    IMPLEMENT_OLETYPELIB(CShapeAppMFCApp, _tlid, 1, 0 )

    These macros provide the TypeInfo implementation for the CShapeAppMFCApp OM.

    In another integration, the same problem symptoms were caused by their MFC application's lack of these macros for its COM object model -- the appObj's IDispatch did not implement GetTypeInfo (returned E_NOT_IMPL):

    ===========

    So when attempting to hookup the application’s OM to the proxy, this call --

    new ComObjectAdapter(…), in HostItemProvider.cs throws an exception:

     IRemoteObjectContract IHostItemProviderContract.GetHostObject(String primaryType, String primaryCookie)

            {

                if (String.Equals(primaryType, m_HostItemProviderClass, StringComparison.Ordinal))

                {

                    m_ComAdapter = new ComObjectAdapter(HostApplication, this.TypeInfrastructureManager);
    ç ‘HostApplication’ argument is System.Object with an IDispatch::GetTypeInfo that returns E_NOTIMPL.   

    ===

    Calling the ComObjectAdapter constructor throws an NotImplementedException  exception.

     This exception was resolved by adding MFC’s DECLARE_/IMPLEMENT_OLETYPELIB into the classes of  the host application’s object model and calling CCmdTarget::EnableTypeLib  in the class constructors of the Application’s object model.  

    This portion: _ComAdapter = new ComObjectAdapter(HostApplication, this.TypeInfrastructureManager); of the VSTA hookup requires that the HostApplication COM object provide type information.  Otherwise, it throws an exception.

    ===========

    Regards,
    Gary

     

  •  02-07-2007, 9:01 PM 265 in reply to 260

    Re: error in HostItemProvider::GetHostobject

     

    thanks for your help. again, gary ^^

    I had better tell something about my situation.

    my app is written in c++ language.

    and my purpose is integrating VSTA to VBA-enabled application.

    my app is integrated with VBA now. most of VBA integration to my app

    is same with VBA-SDK manual.

    and I want to confirm if VSTA can do VBA's job without any problem.

     

    come back to my error,

    and I tried to do same job ( VSTA integration ) to another MFC program.

    It is a sample program in VBA SDK - multipad.

    in two application, same error occurs.

     

    and according to your advice, I inserted

    DECLARE_OLETYPELIB

    IMPLEMENT_OLETYPELIB

    and EnableTypeLib(); ( above two lines needs this line in constructor )

    in my app.

    but error still occurs  -_-

     

    I have 3 sample VSTA inegrated programs.

    one is ShapeAppVBA in your site.

    the others are ShapeAppBasicMFC and ShapeAppAdvancedMFC in VSTA sample ( MS provide these )

    and I can find DECLARE_OLETYPELIB  in ShapeAppBasicMFC and ShapeAppAdvancedMFC.

    but ShapeAppVBA runs correctly  without DECLARE_OLETYPELIB and IMPLEMENT_TYPELIB => oops

     

    I am searching what I missed ... OTL

     

     


    yo man
  •  02-08-2007, 10:31 AM 267 in reply to 265

    Re: error in HostItemProvider::GetHostobject

    Hi Hyun,

    The ShapeAppVBA sample uses APC and supports a more sophisticated COM implementation including Dual interfaces for strong-typed.  The ShapeAppMFC app does not have this support -- it only provides type info via the MFC macros mentioned.  

    Notice this part of the stdafx.h in ShapeAppVBA:

    #include "ShapeAppVBA_tlb.h"

    #include "MFCDUAL.h"

    #include "resource.h"

    #define IfNullRetHR(expr, code) { if (!(expr)) return code; }

    #define IfFailRet(expr) { hr = (expr); if (FAILED(hr)) return hr; }

    #define APC_FORCE_RELEASE

    //#define APC_FORCE_DEBUG

    #include <apcdual.h>

    using namespace MSAPC;

    #define APC_IMPORT_MIDL

    #include <apcmfc.h>

    using namespace MSAPC;

    EXTERN_C const GUID CLSID_ShapeAppControlLibrary;

    ===========

    And notice that the type library is included as a resource in the .RC file

    "1 TYPELIB ""ShapeAppVBA.tlb""\r\n"

    Are you using APC in your VBA-enable app?

    You should follow the ShapeAppVBA sample which includes a walkthrough document that states:

    When you build the solution, a type library named ShapeAppVBA.tlb is created in the %SYSTEMDRIVE%\VSTA\ShapeAppVBA\Core\Debug directory. You will use this type library in the “Creating the Proxy Source DLL” section of this walkthrough.

     

    Follow the walkthrough, and I think that you will make good progress integrating VSTA

    Regards,

    Gary

     

    Filed under:
  •  02-12-2007, 4:12 AM 271 in reply to 267

    Re: error in HostItemProvider::GetHostobject

    Hi Gary

    did you have a good weekend?

    I am not happy because my error is not fixed yet.

    my app is using APC.  and I followed all steps in walkthrough document in ShapeAppVBA.

    and my app's stdafx.h aleady included the code you suggest except MFCDUAL.h.

    but despite I added MFCDUAL.h , the error was not fixed.

    my app's rc file also has the "1 TYPELIB ....."

    I can't find any difference between ShapeAppVBA and my app 's IDL or tlb file ..

    my app's objects inherit IDispatch and implemented GetTypeInfo (because those inhefrit IDispathImpl ) ....

    I want to know what Microsoft.VisualStudio.Tools.Applications.ComTypeAdapter.GetTypeAdapter exactly do.

    I think it require more than GetTypeInfo implementation.

     

    if you have a enough time, you can see the same error after integrating VSTA to Multipad sample in

    VBA SDK.

    ( of course it is your decision , but if you do that for me I will very appreciate your effort to help me ^_^ )

    I have done same job hundreds of times.. I can most of jobs without walkthrough manual because I memorize

    that..;;;

    I hope we can fix this error. thank you^^

     


    yo man
  •  02-12-2007, 5:41 PM 272 in reply to 271

    Re: error in HostItemProvider::GetHostobject

    Hello Hyun,

    Can you get back typeinformation from the IDIspatch you are passing to VSTA?

    Here's how to clean up everything for a clean starting point:

    1. Go to the gac (C:\\windows\\assembly) and uninstall all proxy assemblies
    2. In the properties of the proxy assembly select Signing.  Check ‘Sign the assembly’ check box. Pulldown the ‘Choose a strong name key file:’ combobox and select <new…>
    3. In the key file name enter key.snk (or whatever you wish).  Unselect the ‘Protect my key file with a password’ entry. Click OK
    4. Rebuild proxy.
    5. gacutil – i the proxy assembly in C:\\ShapeAppBasicMFC-IDispatch\\ShapeAppBasicMFC-modified\\Proxy\\bin\\Debug
    6. Confirm that it is installed in C:\\windows\\assembly

    Now run ProjectGen

    7.   Run ProjectGen and select the attached template as input.  Change the naming as desired.  Fix up the directory paths as needed.

    8.   In VSTAHookup.cs change the static string to match the naming and paths used in ProjectGen as this snippet demonstrates.

     

            static String mAppContextName = @"Application";

            static String mHostID = @"ShapeAppMFCSeamless";

            static string mAppAddInPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"ShapeAppBasicMFC-IDispatch\\ShapeAppBasicMFC-modified\\Sample AddIns Seamless");

            static VSTAHookup mSingleton;

     

            internal struct AddInInfo

            {

                internal String mName;

                internal Version mVersion;

                internal bool mIsLoaded;

                internal DateTime mLastLoaded;

            }

            static string mMacroProjectFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"ShapeAppBasicMFC-IDispatch\\ShapeAppBasicMFC-modified\\ShapeAppMFCSeamlessAppAddIn1\\ShapeAppMFCSeamlessAppAddIn1.csproj");

            static string mMacroProjectPath = Path.GetDirectoryName(mMacroProjectFilePath);

            static string mMacroAddInPath = Path.Combine(mMacroProjectPath, @"bin\\debug");

            static string mMacroContextName = @"Macro";

            static string mMacroAssemblyName = @"ShapeAppMFCSeamlessAppAddIn1.dll";

            static string mAppAddInTemplateName = @"ShapeAppMFC SeamlessAddin Template.zip";

            static string mAppAddInTemplateType = @"CSharp";

     

    9.  Change VSTAHookup project’s Build, Output directory to output the assembly into the ShapeAppMFC output directory.  This will allow debugging into vstahookup source.

    Set breakpoints in the proxy methods, the TypeInfrastructureManager methods, the HostItemProvider methods and see if everything is running the same as ShapeAppVBA during the hookup.

    Have you implemented set a break point at this?

    public sealed partial class CShapeAppVBAInitializer {

    public static global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager AddTypesToMap(global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager) {

    . . .

    }

    I will start integrating VSTA with the Multipad sample and let you know how it goes.

    -G

     

View as RSS news feed in XML