-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
PowerShell 7.4.6 along with dbatools 2.1.28 & dbatools.library 2024.4.12 - Microsoft.DataSqlClient.dll - Assembly with same name is already loaded #9566
Comments
I just tried this method from , but getting same error: WrapperScript.ps1Path to the main script$scriptPath = "C:\path\to\CopyJobs.ps1" Use pwsh -c to run the main script in a new sessionpwsh -c "& '$scriptPath'" |
I have also tried the following method: Same error message. |
I was able to get this to run several times, but still testing: Unload the conflicting assembly if it's already loaded$assembly = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq "Microsoft.Data.SqlClient" } Load the required assembly$dllPath = "C:\path\to\Microsoft.Data.SqlClient.dll" I still have to run a clean PS session via the WrapperScript.ps1, but by adding the following on the main script, it seems to work thus far. Still does not explain why the sudden change after updating Powershell and dbatools. |
Have you looked at your Does |
PowerShell 7.4.6
$PROFILE | select *
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\xxx\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\xxx\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Length : 77
cd C:\"Program Files"\PowerShell\7\profile.ps1
- Set-Location: Cannot find path 'C:\Program Files\PowerShell\7\profile.ps1' because it does not exist.
cd C:\"Program Files"\PowerShell\7\Microsoft.PowerShell_profile.ps1
- Set-Location: Cannot find path 'C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1' because it does not exist.
cd C:\Users\xxx\Documents\PowerShell\profile.ps1
- Set-Location: Cannot find path 'C:\Users\xxx\Documents\PowerShell\profile.ps1' because it does not exist.
cd C:\Users\xxx\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
- Set-Location: Cannot find path 'C:\Users\xxx\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' because it does not exist.
So, when I run pwsh and then type pwsh -noprofile, I am able to run the .ps1 script without the Assembly error.
PS C:\Users\xxx> pwsh -NoProfile
PowerShell 7.4.6
PS C:\Users\xxx> cd E:\PS_SCRIPTS\AgentJobs\AG04\
PS E:\PS_SCRIPTS\AgentJobs\AG04> .\CopyAgentJob_AG04_06_FILE.ps1
ComputerName : AG06
InstanceName : FILE
SqlInstance : AG06\FILE
Name : Claim Non-Indexed ACS Ingestion Documents
Status : Dropped
Not sure what that tells us except for my profile is corrupt? How do you suggest I fix this?
Classified as General
From: Matt Cargile ***@***.***>
Sent: Tuesday, January 7, 2025 4:12 PM
To: dataplat/dbatools ***@***.***>
Cc: Crawford, Adam ***@***.***>; Author ***@***.***>
Subject: [External] Re: [dataplat/dbatools] PowerShell 7.4.6 along with dbatools 2.1.28 & dbatools.library 2024.4.12 - Microsoft.DataSqlClient.dll - Assembly with same name is already loaded (Issue #9566)
Have you looked at your $PROFILE | select * files to see if any other modules are being loaded or the like? I am fairly perplexed by your issue. Does Get-DbaAgentJob work if you launch pwsh from the Run Dialog box by hitting WIN + r keys then
Have you looked at your $PROFILE | select * files to see if any other modules are being loaded or the like? I am fairly perplexed by your issue.
Does Get-DbaAgentJob work if you launch pwsh from the Run Dialog box by hitting WIN + r keys then typing pwsh -noprofile?
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/dataplat/dbatools/issues/9566*issuecomment-2576228361__;Iw!!CsmrWXz9mOkSc4Hdn1fjj00!y5toh_tpSr9zpQ9tIHC_fHzr3Yd1l5u19qJhkPhBhTl0sClcUtJmAv7nN5ngLOSWlCWpxBKhSHu205TI6ZXx5ZRg$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BNYFWSNU6UOU2DZLGXZRML32JQ7LRAVCNFSM6AAAAABTW6VLNGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZWGIZDQMZWGE__;!!CsmrWXz9mOkSc4Hdn1fjj00!y5toh_tpSr9zpQ9tIHC_fHzr3Yd1l5u19qJhkPhBhTl0sClcUtJmAv7nN5ngLOSWlCWpxBKhSHu205TI6cWblHsz$>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
This email transmission, including any attachments, is intended solely for the addressee named above, and may contain confidential or privileged information. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender immediately by reply email and destroy the message and its attachments.
|
I wouldn't say corrupt. If you run the below we can see what your $PROFILE.psobject.Properties | ? name -Match host | % { cat $_.value -ea Ignore } If you add a |
I had to run the following to get any output: PS C:\Users\xxx> $PROFILE.psobject.Properties | Where-Object { $_.Name -Match 'host' } | ForEach-Object {
|
Yeah you would only get output if you have a |
This is the error I received after running:
Get-Module
$error[0] | Format-List * -Force
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast…}
Script 2.4.0 beta0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}
Script 22.3.0 SqlServer {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp, Add-SqlAzureAuthenticationContext…}
PSMessageDetails :
Exception : System.Management.Automation.CommandNotFoundException: The 'Copy-DbaAgentJob' command was found in the module 'dbatools', but the module could not be loaded due to the following error: [Couldn't import
C:\program files\powershell\7\Modules\dbatools.library\2024.4.12\core\lib\win-sqlclient\Microsoft.Data.SqlClient.dll | Assembly with same name is already loaded]
For more information, run 'Import-Module dbatools'.
---> System.Management.Automation.CmdletInvocationException: Couldn't import C:\program files\powershell\7\Modules\dbatools.library\2024.4.12\core\lib\win-sqlclient\Microsoft.Data.SqlClient.dll | Assembly
with same name is already loaded
---> System.Management.Automation.RuntimeException: Couldn't import C:\program files\powershell\7\Modules\dbatools.library\2024.4.12\core\lib\win-sqlclient\Microsoft.Data.SqlClient.dll | Assembly with same
name is already loaded
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke[T]()
at System.Management.Automation.CommandDiscovery.AutoloadSpecifiedModule(String moduleName, ExecutionContext context, SessionStateEntryVisibility visibility, Exception& exception)
--- End of inner exception stack trace ---
at System.Management.Automation.CommandDiscovery.TryModuleAutoDiscovery(String commandName, ExecutionContext context, String originalCommandName, CommandOrigin commandOrigin, SearchResolutionOptions
searchResolutionOptions, CommandTypes commandTypes, Exception& lastError)
at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin,
ExecutionContext context)
at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext
context)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject : Copy-DbaAgentJob
CategoryInfo : ObjectNotFound: (Copy-DbaAgentJob:String) [], CommandNotFoundException
FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, E:\PS_SCRIPTS\AgentJobs\CLAIM.ps1: line 26
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
Thanks,
Adam Crawford | Senior SQL Database Administrator | Direct: 513.412.3725 | ***@***.******@***.***>
***@***.***
IT Services |49 E. 4th Street, 400S, Cincinnati, OH 45202
Classified as General
From: Matt Cargile ***@***.***>
Sent: Friday, January 10, 2025 11:57 AM
To: dataplat/dbatools ***@***.***>
Cc: Crawford, Adam ***@***.***>; Author ***@***.***>
Subject: [External] Re: [dataplat/dbatools] PowerShell 7.4.6 along with dbatools 2.1.28 & dbatools.library 2024.4.12 - Microsoft.DataSqlClient.dll - Assembly with same name is already loaded (Issue #9566)
Yeah you would only get output if you have a $PROFILE defined. Ok so it isn't a $PROFILE problem. There is something going on in your session I suppose. You would do a Get-Module and $error[0] | format-list * -force right after the error happens
Yeah you would only get output if you have a $PROFILE defined. Ok so it isn't a $PROFILE problem. There is something going on in your session I suppose. You would do a Get-Module and $error[0] | format-list * -force right after the error happens to retain the entire error. My assumption is there are other commands or modules you are loading that interfere with dbatools so a fresh session solves it.
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/dataplat/dbatools/issues/9566*issuecomment-2583263305__;Iw!!CsmrWXz9mOkSc4Hdn1fjj00!09COTkzFKsWxv1tLCGEyi1yWwH3M7mN_Z-A_fguZj6VOrdmqZ4UXkRxGYcPFxiQNjY503MxLv7OWhJYKF0pfXMP1$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BNYFWSO2TEKXA333TXKMHJD2J73WFAVCNFSM6AAAAABTW6VLNGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBTGI3DGMZQGU__;!!CsmrWXz9mOkSc4Hdn1fjj00!09COTkzFKsWxv1tLCGEyi1yWwH3M7mN_Z-A_fguZj6VOrdmqZ4UXkRxGYcPFxiQNjY503MxLv7OWhJYKF3uV5mcl$>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
This email transmission, including any attachments, is intended solely for the addressee named above, and may contain confidential or privileged information. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender immediately by reply email and destroy the message and its attachments.
|
there's the SqlServer module loaded .... that's the one creating issues |
Yes, @RareCrawdad , you should not load And in my personal opinion, I would drop |
Understood.
So I ran the following:
# Remove the SqlServer module
Remove-Module SqlServer
# Verify the module is removed
Get-Module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast…}
Script 2.4.0 beta0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}
But I am still getting the same error. So how do I successfully remove SQL Server module?
Thanks,
Adam Crawford | Senior SQL Database Administrator | Direct: 513.412.3725 | ***@***.******@***.***>
***@***.***
IT Services |49 E. 4th Street, 400S, Cincinnati, OH 45202
Classified as General
From: Matt Cargile ***@***.***>
Sent: Monday, January 13, 2025 11:33 AM
To: dataplat/dbatools ***@***.***>
Cc: Crawford, Adam ***@***.***>; Mention ***@***.***>
Subject: [External] Re: [dataplat/dbatools] PowerShell 7.4.6 along with dbatools 2.1.28 & dbatools.library 2024.4.12 - Microsoft.DataSqlClient.dll - Assembly with same name is already loaded (Issue #9566)
Yes, @RareCrawdad , you should not load SqlServer module in the same session as dbatools. Or you might be able to get away with always insuring dbatools is loaded first. And in my personal opinion, I would drop SqlServer module altogether if
Yes, @RareCrawdad<https://urldefense.com/v3/__https:/github.com/RareCrawdad__;!!CsmrWXz9mOkSc4Hdn1fjj00!xIgpLNqc1zXQJ293BIWM5D5_v0J0c_lCXBKp3qLV35_4E_V1akMjTZN4NEWwI6tmAP2j9NrXYeMM93m7jawjwgnx$> , you should not load SqlServer module in the same session as dbatools. Or you might be able to get away with always insuring dbatools is loaded first.
And in my personal opinion, I would drop SqlServer module altogether if it is at all possible and only use dbatools. I can't think of any feature SqlServer has that isn't in dbatools though I could very well be wrong.
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/dataplat/dbatools/issues/9566*issuecomment-2587604511__;Iw!!CsmrWXz9mOkSc4Hdn1fjj00!xIgpLNqc1zXQJ293BIWM5D5_v0J0c_lCXBKp3qLV35_4E_V1akMjTZN4NEWwI6tmAP2j9NrXYeMM93m7jcsYrS-W$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BNYFWSM43ZDVK3X4I4VSWEL2KPTDPAVCNFSM6AAAAABTW6VLNGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBXGYYDINJRGE__;!!CsmrWXz9mOkSc4Hdn1fjj00!xIgpLNqc1zXQJ293BIWM5D5_v0J0c_lCXBKp3qLV35_4E_V1akMjTZN4NEWwI6tmAP2j9NrXYeMM93m7jV88G1wZ$>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
This email transmission, including any attachments, is intended solely for the addressee named above, and may contain confidential or privileged information. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender immediately by reply email and destroy the message and its attachments.
|
@RareCrawdad -- once it's in memory, you cant remove it. you have to start a new session w/o sqlserver never having been loaded. |
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Get-DbaAgentJob -SqlInstance $DestinationServer | Where-Object { …
The text was updated successfully, but these errors were encountered: