{"id":2631,"date":"2023-08-01T06:37:07","date_gmt":"2023-08-01T05:37:07","guid":{"rendered":"https:\/\/mortenknudsen.net\/?p=2631"},"modified":"2023-08-01T08:40:53","modified_gmt":"2023-08-01T07:40:53","slug":"error-could-not-load-type-microsoft-graph-authentication-azureidentityaccesstokenprovider-from-assembly-microsoft-graph-core","status":"publish","type":"post","link":"https:\/\/mortenknudsen.net\/?p=2631","title":{"rendered":"ERROR: Could not load type &#8216;Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider&#8217; from assembly &#8216;Microsoft.Graph.Core"},"content":{"rendered":"\n<p>After upgrading <strong>Microsoft Graph<\/strong>, I noticed an issue when trying to run cmdlet <strong>Get-MgGroup<\/strong> or <strong>Get-MgUser<\/strong>. I could connect to Graph with no issues, but multiple cmdlets failed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Error<\/h2>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>Get-MgGroup : Could not load type 'Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider' from assembly 'Microsoft.Graph.Core, Version=1.25\n.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\nAt line:1 char:1\n+ Get-MgGroup -All\n+ ~~~~~~~~~~~~~~~~\n    + CategoryInfo          : NotSpecified: (:) &#91;Get-MgGroup_List], TypeLoadException\n    + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgGroup_List<\/code><\/pre>\n\n\n\n<p>This command did also fail<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&#91;Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>CategoryInfo : InvalidOperation: (Microsoft.Graph\u2026ssTokenProvider:TypeName) &#91;], RuntimeException\n\nFullyQualifiedErrorId : TypeNotFound<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Root Cause<\/h2>\n\n\n\n<p>Even though Microsoft Graph v2.2 installed the version 3.0.9.0 of Microsoft.Graph.Core.Dll, there were multiple versions of Microsoft.Graph.Core.dll found in the $Env:PsModulePath path.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"314\" src=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/GraphVersion.jpg\" alt=\"\" class=\"wp-image-2635\" srcset=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/GraphVersion.jpg 357w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/GraphVersion-300x264.jpg 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>A search found multiple older versions  (1.11, 1.24, 1.25) of Microsoft.Graph.Core.dll  related to <strong>PnP.Powershell<\/strong> module.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"640\" src=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Multiple-DLLs.jpg\" alt=\"\" class=\"wp-image-2632\" srcset=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Multiple-DLLs.jpg 623w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Multiple-DLLs-292x300.jpg 292w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resolution<\/h2>\n\n\n\n<p>Remove older versions of Pnp.Powershell (or other Powershell-modules having old DLLs)<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>uninstall-module -Name PnP.PowerShell -AllVersions<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Issue: Uninstall &#8211; Module x is currently in use &#8230;.<\/h2>\n\n\n\n<p>If you see the below error, it is caused by a dependent DLL being loaded as part of the shell \/ session and therefore in use. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"202\" src=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/In-use-error.jpg\" alt=\"\" class=\"wp-image-2634\" srcset=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/In-use-error.jpg 972w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/In-use-error-300x62.jpg 300w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/In-use-error-768x160.jpg 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution: Module x is currently in use &#8230;.<\/h2>\n\n\n\n<p><strong>Method 1: Remove-Module + Uninstall-Module<\/strong><\/p>\n\n\n\n<p>Run the Remove-Module first to unload the imported module from memory. <\/p>\n\n\n\n<p>After this you can do an uninstall-module<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>Remove-Module -Name &lt;ModuleName> -force\r\nUninstall-Module -Name &lt;ModuleName> -force<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Method 2: Start a CMD and then a Powershell with -NoProfile<\/strong><\/p>\n\n\n\n<p>(1) Close all running Powershell sessions<\/p>\n\n\n\n<p>(2) Start a CMD as local admin <\/p>\n\n\n\n<p>(3) Run the below Powershell-command with the <strong>-NoProfile<\/strong> and <strong>-NonInteractive<\/strong>. Powershell will now be started, without loading any DLLs into the session.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>C:\\&gt;powershell -NoProfile -NonInteractive -Command \"uninstall-module -Name PnP.PowerShell -AllVersions\"<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"988\" height=\"221\" src=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Uninstall-NoShell.jpg\" alt=\"\" class=\"wp-image-2633\" srcset=\"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Uninstall-NoShell.jpg 988w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Uninstall-NoShell-300x67.jpg 300w, https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/Uninstall-NoShell-768x172.jpg 768w\" sizes=\"auto, (max-width: 988px) 100vw, 988px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>After upgrading Microsoft Graph, I noticed an issue when trying to run cmdlet Get-MgGroup or Get-MgUser. I could connect to &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ERROR: Could not load type &#8216;Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider&#8217; from assembly &#8216;Microsoft.Graph.Core\" class=\"read-more button\" href=\"https:\/\/mortenknudsen.net\/?p=2631#more-2631\" aria-label=\"Read more about ERROR: Could not load type &#8216;Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider&#8217; from assembly &#8216;Microsoft.Graph.Core\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2639,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"ngg_post_thumbnail":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[154,55,56,156,133,134,60,132],"tags":[],"class_list":["post-2631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation","category-azure","category-m365-security","category-microsoft-graph","category-microsoft-security","category-mvpbuzz","category-scripting","category-security","infinite-scroll-item","resize-featured-image"],"featured_image_src":"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/fejl-1.jpg","author_info":{"display_name":"Morten Knudsen","author_link":"https:\/\/mortenknudsen.net\/?author=1"},"jetpack_featured_media_url":"https:\/\/mortenknudsen.net\/wp-content\/uploads\/2023\/08\/fejl-1.jpg","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/posts\/2631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2631"}],"version-history":[{"count":9,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/posts\/2631\/revisions"}],"predecessor-version":[{"id":2649,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/posts\/2631\/revisions\/2649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=\/wp\/v2\/media\/2639"}],"wp:attachment":[{"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mortenknudsen.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}