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 import ActiveDirectory module in PowerShell daily20230225.2 build #19238

Open
5 tasks done
gwojan opened this issue Feb 27, 2023 · 11 comments
Open
5 tasks done
Labels
Area-Maintainers-Build specific to affecting the build Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@gwojan
Copy link

gwojan commented Feb 27, 2023

Prerequisites

Steps to reproduce

After installing the latest PowerShell Daily build (daily20230225.2) I am unable to import the ActiveDirectory module

Import-Module ActiveDirectory

Expected behavior

Module should import with no error.

Actual behavior

Import-Module: Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.

Error details

Import-Module: Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.
PS C:\Users\wojang> Get-Error

Exception             :
    Type           : System.Management.Automation.ProviderInvocationException
    ProviderInfo   : Microsoft.ActiveDirectory.Management\ActiveDirectory
    ErrorRecord    :
        Exception             :
            Type           : System.TypeInitializationException
            TypeName       : System.ServiceModel.Diagnostics.TraceUtility
            TargetSite     :
                Name          : SetEtwProviderId
                DeclaringType : System.ServiceModel.Diagnostics.TraceUtility, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
                MemberType    : Method
                Module        : System.ServiceModel.dll
            Message        : The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
            InnerException :
                Type        : System.Configuration.ConfigurationErrorsException
                Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                Errors      :
                    Type        : System.Configuration.ConfigurationErrorsException
                    Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                    Errors      :
                        Type        : System.Configuration.ConfigurationErrorsException
                        Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                        Errors      :
                            Type        : System.Configuration.ConfigurationErrorsException
                            Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                            Errors      :
                                Type        : System.Configuration.ConfigurationErrorsException
                                Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                Errors      :
                                    Type        : System.Configuration.ConfigurationErrorsException
                                    Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                    Errors      : …
                                    BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                    HResult     : -2146232062
                                BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                HResult     : -2146232062
                            BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                            HResult     : -2146232062
                        BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                        HResult     : -2146232062
                    BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                    HResult     : -2146232062
                BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                TargetSite  :
                    Name          : UnsafeGetSectionNoTrace
                    DeclaringType : System.ServiceModel.Configuration.ConfigurationHelpers, System.ServiceModel, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089
                    MemberType    : Method
                    Module        : System.ServiceModel.dll
                Source      : System.ServiceModel
                HResult     : -2146232062
                StackTrace  :
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionNoTrace(String sectionPath)
   at System.ServiceModel.Configuration.DiagnosticSection.UnsafeGetSectionNoTrace()
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
   at System.ServiceModel.Diagnostics.TraceUtility..cctor()
            Source         : System.ServiceModel
            HResult        : -2146233036
            StackTrace     :
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
   at System.ServiceModel.ChannelFactory..ctor()
   at System.ServiceModel.ChannelFactory`1..ctor(Type channelType)
   at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.InitializeChannel[TChannel](TChannel& channel, ChannelFactory`1& chFactory, String
endpointName, CommunicationException& commException)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle
handle, ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList, Boolean propertyNamesOnly)
   at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo, ICollection`1 propertiesToRetrieve)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.InitializeDefaultDrives()
   at System.Management.Automation.SessionStateInternal.InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider,
CmdletProviderContext context)
        CategoryInfo          : InvalidOperation: (:) [], TypeInitializationException
        FullyQualifiedErrorId : InitializeDefaultDrivesException
    Message        : Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.
    InnerException :
        Type           : System.TypeInitializationException
        TypeName       : System.ServiceModel.Diagnostics.TraceUtility
        TargetSite     :
            Name          : SetEtwProviderId
            DeclaringType : System.ServiceModel.Diagnostics.TraceUtility, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
            MemberType    : Method
            Module        : System.ServiceModel.dll
        Message        : The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
        InnerException :
            Type        : System.Configuration.ConfigurationErrorsException
            Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
            Errors      :
                Type        : System.Configuration.ConfigurationErrorsException
                Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                Errors      :
                    Type        : System.Configuration.ConfigurationErrorsException
                    Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                    Errors      :
                        Type        : System.Configuration.ConfigurationErrorsException
                        Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                        Errors      :
                            Type        : System.Configuration.ConfigurationErrorsException
                            Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                            Errors      :
                                Type        : System.Configuration.ConfigurationErrorsException
                                Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                Errors      :
                                    Type        : System.Configuration.ConfigurationErrorsException
                                    Message     : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                    Errors      : …
                                    BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                    HResult     : -2146232062
                                BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                                HResult     : -2146232062
                            BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                            HResult     : -2146232062
                        BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                        HResult     : -2146232062
                    BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                    HResult     : -2146232062
                BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
                HResult     : -2146232062
            BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
            TargetSite  :
                Name          : UnsafeGetSectionNoTrace
                DeclaringType : System.ServiceModel.Configuration.ConfigurationHelpers, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
                MemberType    : Method
                Module        : System.ServiceModel.dll
            Source      : System.ServiceModel
            HResult     : -2146232062
            StackTrace  :
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionNoTrace(String sectionPath)
   at System.ServiceModel.Configuration.DiagnosticSection.UnsafeGetSectionNoTrace()
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
   at System.ServiceModel.Diagnostics.TraceUtility..cctor()
        Source         : System.ServiceModel
        HResult        : -2146233036
        StackTrace     :
   at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
   at System.ServiceModel.ChannelFactory..ctor()
   at System.ServiceModel.ChannelFactory`1..ctor(Type channelType)
   at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.InitializeChannel[TChannel](TChannel& channel, ChannelFactory`1& chFactory, String
endpointName, CommunicationException& commException)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle
handle, ADSearchRequest request)
   at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList, Boolean propertyNamesOnly)
   at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo, ICollection`1 propertiesToRetrieve)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo)
   at Microsoft.ActiveDirectory.Management.Provider.ADProvider.InitializeDefaultDrives()
   at System.Management.Automation.SessionStateInternal.InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider,
CmdletProviderContext context)
    HResult        : -2146233087
TargetObject          : Microsoft.ActiveDirectory.Management\ActiveDirectory
CategoryInfo          : InvalidOperation: (Microsoft.ActiveDir…ent\ActiveDirectory:ProviderInfo) [Import-Module], ProviderInvocationException
FullyQualifiedErrorId : InitializeDefaultDrivesException,Microsoft.PowerShell.Commands.ImportModuleCommand
InvocationInfo        :
    MyCommand        : Import-Module
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : import-Module ActiveDirectory
    PositionMessage  : At line:1 char:1
                       + import-Module ActiveDirectory
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : import-Module
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0-daily20230225.2
PSEdition                      Core
GitCommitId                    7.4.0-daily20230225.2
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@gwojan gwojan added the Needs-Triage The issue is new and needs to be triaged by a work group. label Feb 27, 2023
@SteveL-MSFT
Copy link
Member

The ActiveDirectory module is part of Windows and this issue needs to be reported via the Windows Feedback Tool. This repo doesn't support that module directly.

@SteveL-MSFT SteveL-MSFT added Resolution-External The issue is caused by external component(s). and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Feb 27, 2023
@gwojan
Copy link
Author

gwojan commented Feb 27, 2023

The ActiveDirectory module is part of Windows and this issue needs to be reported via the Windows Feedback Tool. This repo doesn't support that module directly.

Can you explain why I was able to import the module in previous daily builds before daily20230225.2? I was using the ActiveDirectory module in daily20230217.2 just last week.

@daxian-dbw
Copy link
Member

Are you able to import the module in v7.2.10, v7.3.3, and the v7.4.0-preview.1 of PowerShell?

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 28, 2023

Can you explain why I was able to import the module in previous daily builds before daily20230225.2? I was using the ActiveDirectory module in daily20230217.2 just last week.

I guess because we moved to .Net 8 from .Net 7.

@gwojan
Copy link
Author

gwojan commented Feb 28, 2023

Are you able to import the module in v7.2.10, v7.3.3, and the v7.4.0-preview.1 of PowerShell?

@SteveL-MSFT I don't have v7.2.10 installed but ActiveDirectory successfully imports into v7.3.3 and v7.4.0-preview.1. As I mentioned it also still imported with the daily build 20230217.2.

@daxian-dbw daxian-dbw added Area-Maintainers-Build specific to affecting the build Needs-Triage The issue is new and needs to be triaged by a work group. and removed Resolution-External The issue is caused by external component(s). labels Feb 28, 2023
@daxian-dbw
Copy link
Member

Removed the "Resolution" label. We need to keep this issue open and verify if this is caused by moving to .NET 8. /cc @adityapatwardhan @TravisEz13 @SeeminglyScience

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 1, 2023

@daxian-dbw I guess we will have to check all standard Windows modules.

@jborean93
Copy link
Collaborator

jborean93 commented Mar 20, 2023

So I've just taken a stab at investigating this and here is what I've found.

The error occurs in System.ServiceModel and when using a tool like dnspy I put a breakpoint near the problem and found that different assemblies were being loaded. In pwsh 7.3 it loads it from System.Private.ServiceModel.dll but for the 7.4 preview it's using a copy in the GAC. This GAC copy is relying on some configuration file which isn't present and then causing an error when it tries to get an entry in that file.

I'm not sure why it's using the GAC System.ServiceModel as I can load the System.Private.ServiceModel.dll in the pwsh dir just fine. I tried stepping through the Resolve method in CorePsAssemblyLoadContext to figure out why this was happening but nothing relaly jumped out at me. I did notice that Resolve was called with System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 on the preview pwsh version when it loaded the AD cmdlet dll whereas on 7.3 it did not so something is suspicious there to me.

Here is a trace of the assembly resolution when pwsh goes to load the AD cmdlets (top is 7.4 and bottom is 7.3).

image

I'm not sure what else to investigate but there is something going on with how assemblies are being loaded here.

@daxian-dbw
Copy link
Member

daxian-dbw commented Mar 20, 2023

@jborean93 Thank you so much for the investigation!

The package System.ServiceModel.Primitives referenced in Microsoft.PowerShell.SDK.csproj was the version 4.x.0 previously, and became 6.0.0-preview1.23060.3 after moving to .NET 8.

  • In the 4.x.0 versions, the System.ServiceModel.Primitives package would pull in the facade assembly System.ServiceModel.dll, so this assembly was available under $PSHome.

  • In the 6.0.0-preview1.23060.3 version, the System.ServiceModel.Primitives package pulls in System.ServiceModel.Primitives.dll instead, so no more System.ServiceModel.dll under $PSHome. This is why you started to see System.ServiceModel.dll being loaded from GAC now.

So, this regression is caused by the changes in the latest System.ServiceModel.Primitives preview NuGet packages. But I'm not sure if this deems to be a real regression becuase the ActiveDirectory module targets .NET Framework, not .NET, and thus it's sort of by accident that it worked before.

Looping in @SeeminglyScience and @SteveL-MSFT to share their thoughts.

@jborean93
Copy link
Collaborator

But I'm not sure if this deems to be a real regression becuase the ActiveDirectory module targets .NET Framework, not .NET, and thus it's sort of by accident that it worked before.

Even if it isn't deemed to be a real regression I would very much argue that pwsh should solve this problem before 7.4 is actually released due to its popularity on Windows. Going back to the pre Server 2019 days where it used the implicit remoting module is going to break a lot of people's scripts.

@daxian-dbw
Copy link
Member

I agree. Leaving it as is will break a lot of scripts.

For this particular issue, I guess we will have to lock the versions of the System.ServiceModel.xxxxx NuGet package to be 4.x.x.
But supporting ActiveDirectory will be fragile in long term, as it may stop working due to a different change in .NET or the packages pwsh depends on.

I think we should plan ahead. One option is that we lock the version of those packages in 7.4 to keep ActiveDirectory working in this LTS, but at the same time, we start to advertise via blog and other channels that ActiveDirectory will stop working starting from 7.5 and up. It would be the best if ActiveDirectory module can be updated to work on both Windows PowerShell and pwsh natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Maintainers-Build specific to affecting the build Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

5 participants