dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Watch-DbaXESession errors every time, because SqlServer.XEvent could not be loaded.

Open ReeceGoding opened this issue 9 months ago • 1 comments

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.

ReeceGoding avatar Mar 04 '25 22:03 ReeceGoding

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

  1. Importing sqlserver before dbatools
  2. 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.

Image

Semoxea avatar Apr 10 '25 12:04 Semoxea

try again with the newest version and report back pls 🙏🏼

potatoqualitee avatar Jul 20 '25 07:07 potatoqualitee

Also see #9720

andreasjordan avatar Jul 24 '25 17:07 andreasjordan

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.

ReeceGoding avatar Jul 26 '25 12:07 ReeceGoding

@potatoqualitee Same result on Windows as in the original post. My version is 2.5.1.

ReeceGoding avatar Jul 26 '25 12:07 ReeceGoding

@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.

ReeceGoding avatar Jul 26 '25 12:07 ReeceGoding

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.

potatoqualitee avatar Aug 05 '25 23:08 potatoqualitee

oh wait, i think this was fixed by @andreasjordan WOO. Closed as fixed unless reported otherwise.

potatoqualitee avatar Aug 05 '25 23:08 potatoqualitee

@potatoqualitee It works on Linux, so I'm not even going to try Windows. It'll work.

ReeceGoding avatar Aug 08 '25 20:08 ReeceGoding