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

[Bug] Remove-DbaDbUser - failed with: Constructor on type 'Microsoft.SqlServer.Management.Smo.SqlObjectUnion' not found #7498

Closed
1 task
ksl28 opened this issue Jul 6, 2021 · 4 comments
Labels
bugs life confirmed Label to be used by maintainers that confirm a bug does exist for the given issue ps core PowerShell Core (7+) smo

Comments

@ksl28
Copy link

ksl28 commented Jul 6, 2021

Report

Remove-DbaDbUser gives an exception message, if executed through Powershell Core.
The user is still dropped, but it generates an exception.

Host used

  • [ X] powershell.exe
  • [ X] ISE
  • [ X] VS Code
  • Other (please specify)

Errors Received

PSMessageDetails      :
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "EnumOwnedObjects" with "0" argument(s): "Constructor on type 'Microsoft.SqlServer.Management.Smo.SqlObjectUnion' not found."
                         ---> System.MissingMethodException: Constructor on type 'Microsoft.SqlServer.Management.Smo.SqlObjectUnion' not found.
                           at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
                           at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
                           at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.SmoManagementUtil.CreateInstance(Assembly assembly, String objectType)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.CreateObjectInstance(Assembly assembly, String objectType)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.CreateObjectInstance(String assemblyName, String objectType)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.LoadElement(ObjectLoadInfo oli)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.LoadElement(ObjectLoadInfo oli, ServerVersion ver, DatabaseEngineType databaseEngineType, DatabaseEngineEdition databaseEngineEdition)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.GetElement(ObjectLoadInfo oli, ServerVersion ver, DatabaseEngineType databaseEngineType, DatabaseEngineEdition databaseEngineEdition)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.ObjectCache.GetAllElements(Urn urn, ServerVersion ver, DatabaseEngineType databaseEngineType, DatabaseEngineEdition databaseEngineEdition, Object ci)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetObjectsFromCache(Urn urn, Object ci)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData(Request req, Object ci)
                           at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object connectionInfo, Request request)
                           at Microsoft.SqlServer.Management.Smo.ExecutionManager.GetEnumeratorDataReader(Request req)
                           at Microsoft.SqlServer.Management.Smo.PermissionWorker.EnumOwnedObjects(SqlSmoObject obj)
                           at CallSite.Target(Closure , CallSite , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
                           at CallSite.Target(Closure , CallSite , Object )
                           at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                           at System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          :
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : MissingMethodException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Remove-DbUser, C:\Users\krle_admin\Documents\PowerShell\Modules\dbatools\1.0.168\allcommands.ps1: line 62567
                        at Remove-DbaDbUser<Process>, C:\Users\krle_admin\Documents\PowerShell\Modules\dbatools\1.0.168\allcommands.ps1: line 62677
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

Steps to Reproduce

Remove-DbaDbUser -SqlInstance SQLInstance -Database "Database-Name" -User "SomeUserName"

Expected Behavior

I expected the command to run through, without any errors, since its actually doing what its supposed to do.

Actual Behavior

It failed with an exception message:
Line |
62567 | … $schemaUrns = $user.EnumOwnedObjects() | Where-Object Typ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "EnumOwnedObjects" with "0" argument(s): "Constructor on type
| 'Microsoft.SqlServer.Management.Smo.SqlObjectUnion' not found."

Environmental information

🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
Please provide the output of the below script

PowerShell Version        : 7.1.3
dbatools latest installed : 1.0.168
Culture of OS             : en-GB

SQL Server:

/* Microsoft SQL Server 2017 (RTM-CU15) (KB4498951) - 14.0.3162.1 (X64)   May 15 2019 19:14:30   Copyright (C) 2017 Microsoft Corporation  Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: ) (Hypervisor)  */
/*us_english*/
@ksl28 ksl28 added the bugs life label Jul 6, 2021
@andreasjordan
Copy link
Contributor

This is a problem of the SMO we use. See:
microsoft/sqlmanagementobjects#2
microsoft/sqlmanagementobjects#48

Both are closed, issue should be fixed with SMO version 161.40241.8 and newer.
@potatoqualitee - do you see a chance to use these SMO instead of those from SqlServer?

@andreasjordan andreasjordan changed the title [Bug] [Bug] Remove-DbaDbUser - failed with: Constructor on type 'Microsoft.SqlServer.Management.Smo.SqlObjectUnion' not found Jul 6, 2021
@andreasjordan andreasjordan added confirmed Label to be used by maintainers that confirm a bug does exist for the given issue ps core PowerShell Core (7+) labels Jul 6, 2021
@potatoqualitee
Copy link
Member

I've found it very challenging in the past, but will try it. Let's see.

@potatoqualitee
Copy link
Member

Yeah, unfortunately, I have no clue how to get the SMO library in the nuget to work.

image

The best way is to replace them with the SMO that @Matteo-T generates with a magic formula 😅

@potatoqualitee
Copy link
Member

fixed in dev! will release to ps gallery in about 5 days after thorough testing

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs life confirmed Label to be used by maintainers that confirm a bug does exist for the given issue ps core PowerShell Core (7+) smo
Projects
None yet
Development

No branches or pull requests

3 participants