Watch-DbaXESession errors every time, because SqlServer.XEvent could not be loaded.
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Any attempts to run Watch-DbaXESession have me informed that
The module 'SqlServer.XEvent' could not be loaded. For more information, run 'Import-Module SqlServer.Xevent'.
Any attempts to import the module fail. I already clearly have the plain SqlServer module imported and working.
Steps to Reproduce
Get-DbaXESession -SqlInstance YourBox -Session 'Yours' | Watch-DbaXESession
Please confirm that you are running the most recent version of dbatools
2.1.29
Other details or mentions
A possibly related issue is that Export-DbaXECsv always warns me that I'm missing XESmartTarget.Core.dll, but I've made no attempt to investigate that.
What PowerShell host was used when producing this error
Windows PowerShell (powershell.exe)
PowerShell Host Version
5.1.22621.4391
SQL Server Edition and Build number
Tried on 2022 boxes.
.NET Framework Version
Very recent.
I got the same issue. Probably related, or the same as described in issue #9033. I am trying to read a local .sqlaudit file with Read-DbaAuditFile -Path "c:\path\to\audit.sqlaudit" and it throws the same error. I tried it with importing sqlserver module before importing dbatools, importing the other way around (to check for assembly issues, because the Read-SQLXevent Assembly in dbatools gave me issues sometime before with constructor overload). I tried it on 2022 and 2019. Same thing. Dbatools version 2.1.30.
Edit: I found the underlying issue, the same i already had and mentioned. When you're importing sqlserver Module first thing in a fresh Powershell and run Read-SQLXEvent -FileName "xxx", it works fine. Now, importing dbatools first, or running Read-DbaAuditFile doesn't work, because the XEventLite.dll Assembly that gets shipped with dbatools doesn't have that function (or at least not with the right parameters?). Read-DbaAuditFile still does not work in that case though.
When I try to work around the issue by importing sqlserver first, then running Read-SqlXevent (and just not use Read-DbaAuditFile), i get an error while importing dbatools:
import-module : Could not import C:\Program
Files\WindowsPowerShell\Modules\dbatools.library\2024.4.12\desktop\lib\Azure.Core.dll : Import-Module :
Could not load file or assembly 'System.ClientModel, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
At C:\Program Files\WindowsPowerShell\Modules\dbatools.library\2024.4.12\dbatools.library.psm1:186 char:21
Funnily enough that issue only occurs when
- Importing sqlserver before dbatools
- During the first import attempt of dbatools after sqlserver Module is already loaded in the session
See image below
When I try another attempt to import the module after having imported sqlserver, it works fine. Still can't use Read-DbaAuditFile in any case of that though.
try again with the newest version and report back pls 🙏🏼
Also see #9720
try again with the newest version and report back pls 🙏🏼
Couldn't get it to work on 2.5.1 on Linux. Will try Windows soon.
@potatoqualitee Same result on Windows as in the original post. My version is 2.5.1.
@andreasjordan I'm not sure if you're asking my to test a particular cmdlet, but I think it's safe to assume from the above that it won't work.
Please try in 2.5.5. I think i forgot to address this one and if so, I'll fix it and give you a preview version.
oh wait, i think this was fixed by @andreasjordan WOO. Closed as fixed unless reported otherwise.
@potatoqualitee It works on Linux, so I'm not even going to try Windows. It'll work.