COM Addin throw IDispatchNotImplementedException: Instance behind proxy doesn't implement IDispatch.
ablersch opened this issue · comments
Hi,
I updated an solution from NetOffice 1.7.4 to NetOfficeFw 1.9.2. My addin add some ui elements and e.g. change the content of a word document.
Now in Addin_OnConnection
the factory throws IDispatchNotImplementedException
:
NetOffice.Exceptions.IDispatchNotImplementedException: Instance behind proxy doesn't implement IDispatch.
bei NetOffice.CoreFactoryExtensions.TypeGuid(Object comProxy)
bei NetOffice.CoreFactoryExtensions.GetFactoryInfo(Core value, Dictionary`2 hostCache, ICOMObject caller, Object comProxy, Boolean wantTheDuck, Boolean throwException)
bei NetOffice.Core.CreateObjectFromComProxy(ICOMObject caller, Object comProxy, Boolean allowDynamicObject)
bei Company.App.Addin.Addin_OnConnection(Object applicationObject, ext_ConnectMode connectMode, Object addInInst, Array& custom)
Have I forgotten to change something or what can I do?
[COMAddin("Company.App", "App", LoadBehavior.LoadAtStartup), CustomUI("Company.App.RibbonUI.xml")]
[RegistryLocation(RegistrySaveLocation.LocalMachine)]
[Guid("3174550e-bc3c-42fa-a5b9-5bd7664d678e"), ProgId("Company.App.Addin"), ComVisible(true)]
[MultiRegister(RegisterIn.Excel, RegisterIn.Word, RegisterIn.Outlook, RegisterIn.PowerPoint)]
[Tweak(false)]
public class Addin : COMAddin
{
private ICOMObject application;
public Addin()
{
this.OnStartupComplete += Addin_OnStartupComplete;
this.OnConnection += Addin_OnConnection;
this.OnDisconnection += Addin_OnDisconnection;
}
private void Addin_OnConnection(object applicationObject, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
try
{
Shared.Utils.LogDebug($"Addin_OnConnection. Addin connected to application. Mode: {connectMode}");
application = Factory.CreateObjectFromComProxy(null, application, true);
....
}
catch (Exception exception)
{
Shared.Utils.LogError(exception, "Addin_OnConnection");
}
}
}
If I set Tweak(true)
I got a null reference exception:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei NetOffice.OfficeApi.Tools.COMAddin.TryDetectHostRegistryKey(Object applicationProxy)
bei NetOffice.OfficeApi.Tools.COMAddin.NetOffice.Tools.Native.IDTExtensibility2.OnConnection(Object application, ext_ConnectMode ConnectMode, Object AddInInst, Array& custom).
Hi @ablersch, the COMAddin
already has the Application
property so you does not have to create another object from the object applicationObject
parameter.
Please see https://github.com/NetOfficeFw/NetOffice/tree/main/Examples for how to use NetOffice.
Thanks, that was my problem. Now it's working.