Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Task Pane does not work in MS Word #280

Closed
jozefizso opened this issue Jul 26, 2020 · 8 comments
Closed

Custom Task Pane does not work in MS Word #280

jozefizso opened this issue Jul 26, 2020 · 8 comments

Comments

@jozefizso
Copy link
Member

jozefizso commented Jul 26, 2020

I have written an AddIn using NetOfficeFw and it works great on my development machine but I am having trouble installing it on any other workstation. I have run RegAsm.exe on the .DLL and it reports "Types registered successfully" but when I launch Word it cannot create the custom task pane from my AddIn. Getting more insight with more descriptive error messages for what is behind this would definitely be helpful!

My AddIn is defined with the following attributes:

[ComVisible(true)]
[COMAddin("AutoDocsToolbox", "AutoDocs Toolbox", LoadBehavior.LoadAtStartup)]
[ProgId("AutoDocsToolbox.Addin"), Guid("6F747690-3C89-4255-B191-82CDCFAE8813")]
[CustomUI("RibbonUI.xml", true)]
[CustomPane(typeof(AutoDocsToolboxPane), "AutoDocs Toolbox", true, PaneDockPosition.msoCTPDockPositionRight, PaneDockPositionRestrict.msoCTPDockPositionRestrictNone, 460, 800)]
public class Addin : Word.Tools.COMAddin
{
...
}
---------------------------
AutoDocs ToolBox
---------------------------
An error occurend in CTPFactoryAvailable
Unable to create NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane(AutoDocs Toolbox).System.Runtime.InteropServices.COMException (0x80004005): Unable to create NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane(AutoDocs Toolbox). ---> NetOffice.Exceptions.MethodCOMException (0x80004005): Failed to proceed Method on Office.ICTPFactory=>CreateCTP. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Unable to create specified ActiveX control.
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at NetOffice.Invoker.MethodReturn(ICOMObject comObject, String name, Object[] paramsArray)
   at NetOffice.Invoker.MethodReturn(ICOMObject comObject, String name, Object[] paramsArray)
   at NetOffice.CoreMethodExtensions.ExecuteBaseReferenceMethodGet[T](Core value, ICOMObject caller, String name, Object[] paramsArray)
   at NetOffice.CoreMethodExtensions.ExecuteBaseReferenceMethodGet[T](Core value, ICOMObject caller, String name, Object argument1, Object argument2)
   at NetOffice.OfficeApi.Tools.CustomTaskPaneHandler.CreateCTP(Core factory, ICTPFactory taskPaneFactory, String fullName, String title, OnErrorHandler onError)NetOffice.Exceptions.MethodCOMException (0x80004005): Failed to proceed Method on Office.ICTPFactory=>CreateCTP. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Unable to create specified ActiveX control.
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at NetOffice.Invoker.MethodReturn(ICOMObject comObject, String name, Object[] paramsArray)
   at NetOffice.Invoker.MethodReturn(ICOMObject comObject, String name, Object[] paramsArray)
   at NetOffice.CoreMethodExtensions.ExecuteBaseReferenceMethodGet[T](Core value, ICOMObject caller, String name, Object[] paramsArray)
   at NetOffice.CoreMethodExtensions.ExecuteBaseReferenceMethodGet[T](Core value, ICOMObject caller, String name, Object argument1, Object argument2)
   at NetOffice.OfficeApi.Tools.CustomTaskPaneHandler.CreateCTP(Core factory, ICTPFactory taskPaneFactory, String fullName, String title, OnErrorHandler onError)System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Unable to create specified ActiveX control.
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at NetOffice.Invoker.MethodReturn(ICOMObject comObject, String name, Object[] paramsArray)System.Runtime.InteropServices.COMException (0x80004005): Unable to create specified ActiveX control.
---------------------------
OK   
---------------------------

Originally posted by @chadknudson in #271 (comment)

@jozefizso
Copy link
Member Author

jozefizso commented Jul 27, 2020

Hi @chadknudson,
is your custom task pane class AutoDocsToolboxPane exposed to COM as well?

AutoDocsToolboxPane must have [ComVisible(true)] and [Guid()] attributes. You can define ProgId, but it must exactly match the full name of AutoDocsToolboxPane class (namespace + class name).

@chadknudson
Copy link

I have the AutoDocsToolboxPane decorated with the following attributes:

namespace NorseTechnologies.AutoDocs.Tools
{
[ComVisible(true)]
[Guid("68058A6B-705E-4E4D-A0E1-8943625B6FE8")]
[ProgId("NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane")]
public partial class AutoDocsToolboxPane : UserControl, Word.Tools.ITaskPane
{
...
}
}

@jozefizso
Copy link
Member Author

jozefizso commented Jul 27, 2020

That looks good, both of your classes should be accessible from COM when defined this way.

One quick way to check is to use PowerShell:

New-Object -ComObject "NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane"

This may reveal more details about why the class cannot be created from COM.

@chadknudson
Copy link

chadknudson commented Jul 27, 2020

This is what the PowerShell command produced when running PowerShell in 64-bit:

New-Object : Retrieving the COM class factory for component with CLSID {68058A6B-705E-4E4D-A0E1-8943625B6FE8} failed
due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:1

  • New-Object -ComObject "NorseTechnologies.AutoDocs.Tools.AutoDocsToolb ...
  •   + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
      + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
    
    

I wrapped the command into a script that would force PowerShell to run in 32-bit:

if ($env:Processor_Architecture -ne "x86")
{ write-warning 'Launching x86 PowerShell'
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -noninteractive -noprofile -file $myinvocation.Mycommand.path -executionpolicy bypass
exit
}
"Always running in 32bit PowerShell at this point."
$env:Processor_Architecture
[IntPtr]::Size
New-Object -ComObject "NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane"

When running the PowerShell script to force PowerShell to run as 32-bit on the target machine I am trying to deploy to I got:

New-Object : Retrieving the COM class factory for component with CLSID {68058A6B-705E-4E4D-A0E1-8943625B6FE8} failed
due to the following error: 80070002 The system cannot find the file specified. (Exception from HRESULT: 0x80070002).
At S:\AutoDocs\Apps\TestCreateToolPane.ps1:9 char:1

  • New-Object -ComObject "NorseTechnologies.AutoDocs.Tools.AutoDocsToolb ...
  •   + CategoryInfo          : NotSpecified: (:) [New-Object], FileNotFoundException
      + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewObjectCommand
    
    

Running the PowerShell script as 32-bit on my developer machine worked successfully:

PS D:\temp\PowerShell> .\TestCreateToolPane.ps1
WARNING: Launching x86 PowerShell
Always running in 32bit PowerShell at this point.
x86
4

AutoSize : False
AutoSizeMode : GrowOnly
AutoValidate : EnablePreventFocusChange
BorderStyle : None
Text :
AutoScaleDimensions : {Width=6, Height=13}
AutoScaleMode : Font
BindingContext : {}
ActiveControl :
CurrentAutoScaleDimensions : {Width=6, Height=13}
ParentForm :
AutoScroll : False
AutoScrollMargin : {Width=0, Height=0}
AutoScrollPosition : {X=0,Y=0}
AutoScrollMinSize : {Width=0, Height=0}
DisplayRectangle : {X=0,Y=0,Width=445,Height=685}
HorizontalScroll : System.Windows.Forms.HScrollProperties
VerticalScroll : System.Windows.Forms.VScrollProperties
DockPadding :
AccessibilityObject : ControlAccessibleObject: Owner =
NorseTechnologies.AutoDocs.Tools.AutoDocsToolboxPane
AccessibleDefaultActionDescription :
AccessibleDescription :
AccessibleName :
AccessibleRole : Default
AllowDrop : False
Anchor : Top, Left
AutoScrollOffset : {X=0,Y=0}
LayoutEngine : System.Windows.Forms.Layout.DefaultLayout
BackColor : Color [Control]
BackgroundImage :
BackgroundImageLayout : Tile
Bottom : 685
Bounds : {X=0,Y=0,Width=445,Height=685}
CanFocus : False
CanSelect : True
Capture : False
CausesValidation : True
ClientRectangle : {X=0,Y=0,Width=445,Height=685}
ClientSize : {Width=445, Height=685}
CompanyName : NorseTechnologies.AutoDocs.Tools
ContainsFocus : False
ContextMenu :
ContextMenuStrip :
Controls : {System.Windows.Forms.TabControl, TabPages.Count: 3, TabPages[0]: TabPage:
{Bookmark Navigator}}
Created : True
Cursor : [Cursor: Default]
DataBindings : {}
DeviceDpi : 96
IsDisposed : False
Disposing : False
Dock : None
Enabled : True
Focused : False
Font : [Font: Name=Microsoft Sans Serif, Size=8.25, Units=3, GdiCharSet=0,
GdiVerticalFont=False]
ForeColor : Color [ControlText]
Handle : 329424
HasChildren : True
Height : 685
IsHandleCreated : True
InvokeRequired : False
IsAccessible : False
IsMirrored : False
Left : 0
Location : {X=0,Y=0}
Margin : {Left=3,Top=3,Right=3,Bottom=3}
MaximumSize : {Width=0, Height=0}
MinimumSize : {Width=0, Height=0}
Name : AutoDocsToolboxPane
Parent :
ProductName : AutoDocsToolbox
ProductVersion : 1.0.0.0
RecreatingHandle : False
Region :
Right : 445
RightToLeft : No
Site :
Size : {Width=445, Height=685}
TabIndex : 0
TabStop : True
Tag :
Top : 0
TopLevelControl :
UseWaitCursor : False
Visible : True
Width : 445
WindowTarget : System.Windows.Forms.Control+ControlNativeWindow
PreferredSize : {Width=0, Height=0}
Padding : {Left=0,Top=0,Right=0,Bottom=0}
ImeMode : NoControl
Container :

@chadknudson
Copy link

Is this possibly a 32-bit/64-bit issue?

My project properties for the AddIn project platform target : x86.

The systems to which I am attempting to deploy the AddIn are all running 64-bit Windows 10 Professional and Microsoft Word 2019 MSO (16.0.13001.20266) 32-bit.

My development system is Windows 10 Professional with Microsoft Word 2019 MSO (16.0.13001.20266) 32-bit as well.

@chadknudson
Copy link

Please close the issue and mark it an ID10T issue. I was missing a DLL in the setup program of my AddIn. I had added a dependency on a new Nuget package and forgot to add the corresponding .DLL to my setup application.

@jozefizso
Copy link
Member Author

Is this possibly a 32-bit/64-bit issue?

Yes, this is also common situation to look for - you should ensure you are calling right version of regasm.exe depending on which bitness you need to support.

32-bit regasm: C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
64-bit regasm: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe

By default, the 32-bit version of regasm is used by command line, so it will work for your 32-bit MS Office (even on 64-bit Windows)

@jozefizso
Copy link
Member Author

@chadknudson No problem, this happens. I went this round countless times. I know how complicated this system is and what I should be looking for and yet I miss such details myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants