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

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope]. #5

Closed
kamilNope opened this issue Jan 7, 2021 · 19 comments
Closed

Comments

@kamilNope
Copy link

@kamilNope kamilNope commented Jan 7, 2021

Run new office onenote with admin permissions and powershell with admin permissions
Version Windows 10 Pro
Version 20H2
Compilation 19042.631

Error Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
At C:\GIT\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:357 char:31
... erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (Microsoft.Offic....HierarchyScope:TypeName) [], RuntimeException
FullyQualifiedErrorId : TypeNotFound

@aparente
Copy link

@aparente aparente commented Jan 11, 2021

Getting this same error on a Windows 10 Pro VM running on Azure. Running in Powershell administrative mode.

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed
due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\Users\aparente\Documents\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertO
neNote2MarkDown-v2.ps1:721 char:16
+     $OneNote = New-Object -ComObject OneNote.Application
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
At C:\Users\aparente\Documents\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertO
neNote2MarkDown-v2.ps1:724 char:31
+ ... erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic....HierarchyScope:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Total links found       :       0
        Matched         :       0
        Ambiguous       :       0
        Not matched     :       0
Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At C:\Users\aparente\Documents\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertO
neNote2MarkDown-v2.ps1:928 char:5
+     [System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNo ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

Remove-Variable : Cannot find a variable with the name 'OneNote'.
At C:\Users\aparente\Documents\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertO
neNote2MarkDown-v2.ps1:929 char:5
+     Remove-Variable OneNote
+     ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand

@thanhphu
Copy link

@thanhphu thanhphu commented Jan 15, 2021

Make sure that you are running the Office version, not the Windows Store version of One Note.

What's the difference? The Office version has a slightly taller ribbon (3 lines) instead of 1 line in the Windows Store version

Office version
onenoteoffice

Store version
Screen Shot 2021-01-15 at 01 33 20 PM

@nixsee
Copy link

@nixsee nixsee commented Jan 19, 2021

Sorry for being late to this - did @thanhphu 's suggestion work? Yes, it is necessary (and advisable, due to better features) to use the Office version, which is free here https://www.onenote.com/Download

@rustam-python
Copy link

@rustam-python rustam-python commented Feb 22, 2021

The same problem. I tried with The Office version.

InvalidOperation: K:\tmp\OneNote\ConvertOneNote2MarkDown-2.5\ConvertOneNote2MarkDown-v2.ps1:357:31
Line |
 357 |  … erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].

0

Upd. My bad - it works if PowerShell and OneNote (The Office version, not usual one!) are both started as Administrator.

@nixsee
Copy link

@nixsee nixsee commented Feb 22, 2021

@rustam-python just curious, what caused your initial problem? Did you use Office version or Windows Store version? Admin or normal?

@rustam-python
Copy link

@rustam-python rustam-python commented Feb 22, 2021

@rustam-python just curious, what caused your initial problem? Did you use Office version or Windows Store version? Admin or normal?

Script is not working with OneNote started as Administrator and PowerShell started as non-Administrator. In all tries I used The Office Version of OneNote.

@nixsee
Copy link

@nixsee nixsee commented Feb 22, 2021

Thanks. So it was just the admin status not matching. Yeah, that's covered in the instructions, so I won't look into this any further and close the issue.

@nixsee nixsee closed this Feb 22, 2021
@slappycat2
Copy link

@slappycat2 slappycat2 commented May 28, 2021

Hi Nixsee, Not sure why you closed this. He said he is still running into the same problem and I am too. I'm running 2016, Desktop version, both, VS Code and OneNote, running as admin, and I get the exact same error. Any ideas?

@nixsee
Copy link

@nixsee nixsee commented May 28, 2021

@slappycat2 I closed it because it is a user error issue - they didn't read the instructions.

Try running Powershell directly, rather than in VS Code - perhaps the Powershell in VS Code is not running as Admin. Alternatively, run both without admin (I don't use admin for either when I run it).

Moreover, these errors are outside of the scope of the script - they are a windows/powershell/office problem which each person will have to resolve for themselves.

@slappycat2
Copy link

@slappycat2 slappycat2 commented May 29, 2021

Tried all of the above and no luck. I'll keep playing with it.

UPDATE - For others running into this issue, I got it working, finally. The key for me turned out to be that I had to run it in the Powershell ISE (not just the Powershell). So, to recap:

  1. Run OneNote as Admin
  2. Use PS ISE as ADMIN.
  3. Set-ExecutionPolicy Bypass -Scope Process (Answer Yes-To-All, when prompted)
  4. Run the program at the commandline.
    HTH!

@nixsee
Copy link

@nixsee nixsee commented May 29, 2021

Good to hear you got it working. Does normal Powershell work if you run "Set-ExecutionPolicy Bypass -Scope Process" in it?

@slappycat2
Copy link

@slappycat2 slappycat2 commented May 29, 2021

@nixsee: No, it didn't. I had to use ADMIN, too. If I find anything else worth sharing, I'll post here! Thanks!

@rustam-python
Copy link

@rustam-python rustam-python commented May 29, 2021

Good to hear you got it working. Does normal Powershell work if you run "Set-ExecutionPolicy Bypass -Scope Process" in it?

My bad - I forgot to mention that last time. Yes, firstly I tried without Set-ExecutionPolicy Bypass -Scope Process - it is not worked. After I enabled it - it was ok.

@nixsee
Copy link

@nixsee nixsee commented May 29, 2021

Good to hear. So, just to be thorough, does normal PowerShell (not ISE) work in non-admin mode (OneNote in non-admin as well) if you run it with Set-ExecutionPolicy Bypass -Scope Process? Or does it only work with admin and set-executionpolicy?

@rustam-python
Copy link

@rustam-python rustam-python commented May 29, 2021

Good to hear. So, just to be thorough, does normal PowerShell (not ISE) work in non-admin mode (OneNote in non-admin as well) if you run it with Set-ExecutionPolicy Bypass -Scope Process? Or does it only work with admin and set-executionpolicy?

No, only in admin mode with Set-ExecutionPolicy Bypass -Scope Process.

@nixsee
Copy link

@nixsee nixsee commented May 29, 2021

Ok, so pretty much as I have described in the Readme...

image

Hopefully no one else will need to raise an issue about this again, now that it is all documented clearly here

@leojonathanoh
Copy link
Member

@leojonathanoh leojonathanoh commented Jul 29, 2021

Just wanted to leave a note to future readers that this happens because the script requires Powershell 5 (Powershell ISE will work too). The error shows up on pwsh (aka powershell core, aka Powershell >=6).

In contrast to the suggestion above #5 (comment), the script does not require admin privileges. Set-ExecutionPolicy Bypass -Scope Process is required, as described in the readme.

@leojonathanoh
Copy link
Member

@leojonathanoh leojonathanoh commented Jul 30, 2021

Support for powershell core added in #43.

If this happens on Windows Powershell <=5.x then perhaps its due to missing Onenote assemblies because the user might not have installed the desktop version of Onenote 2016. Warning message about this added in #44.

Both will be included in v2.10.0.

If this still happens, please post your environment so we can find out the cause.

@mikevel
Copy link

@mikevel mikevel commented Sep 9, 2021

FWIW, I also encountered the same issue while running the script in PowerShell Core 7 with Office 2021 and the solution was to run the script from PowerShell 5 with Set-ExecutionPolicy Bypass -Scope Process -- no admin privileges required.

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

Successfully merging a pull request may close this issue.

None yet
8 participants