Visitar URL original
System.Diagnostics.PerformanceCounter.InitializeImpl() error · Issue #3595 · dotnet/SqlClient · GitHub
Skip to content

System.Diagnostics.PerformanceCounter.InitializeImpl() error #3595

Description

@EcTomBot

Describe the bug

After upgrading the library from version 6.0.2 to version 6.1.1, creating a connection to SQL Server

string connectionString = @"Data Source=SERVER\SQL2016;Initial Catalog=GeOM;Integrated Security=True;User ID=;Password=;MultipleActiveResultSets=True;Application Name=EntityFramework;Encrypt=False";
SqlConnection _connection = new SqlConnection(connectionString);

generates the following error:

Exception message:
System.InvalidOperationException
Applicazione: GeOM.exe
Versione framework: v4.0.30319
Descrizione: il processo è stato terminato a causa di un'eccezione non gestita.

Stack trace:
Informazioni sull'eccezione: System.InvalidOperationException
   in System.Diagnostics.PerformanceCounter.InitializeImpl()
   in System.Diagnostics.PerformanceCounter.Increment()
   in Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolKey, Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolGroupOptions, Microsoft.Data.Common.ConnectionString.DbConnectionOptions ByRef)
   in Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolKey)
   in Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(System.String)
   in Microsoft.Data.SqlClient.SqlConnection..ctor(System.String, Microsoft.Data.SqlClient.SqlCredential)
   in Microsoft.Data.SqlClient.SqlConnection..ctor(System.String)
   in AgileCom.Entities.Infrastructure.Avvisi.Repository.AvvisiRepositoryDapper..ctor(System.String)
   in OM.Anagrafiche.MessaggioAvvisiVM..ctor()
   in OM.Anagrafiche.ucEtichettaConAvvisi..ctor()

Informazioni sull'eccezione: System.Windows.Markup.XamlParseException
   in System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   in System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   in System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   in System.Windows.Application.LoadComponent(System.Object, System.Uri)
   in OM.Commesse.frmPosizione.InitializeComponent()
   in OM.Commesse.frmPosizione..ctor(Boolean)
   in OM.Commesse.frmCommesse+<>c__DisplayClass170_0.<ApriPosizione>b__0()
   in OM.MainWindow.OpenTab(System.Func`1<System.Windows.Controls.UserControl>, System.String, OM.UIOpenModality, Boolean, System.String)
   in OM.Commesse.frmCommesse.ApriPosizione(OM.Entities.Com_Posizione)
   in OM.Commesse.frmCommesse.tvPosizioni_RowDoubleClick(System.Object, DevExpress.Xpf.Grid.RowDoubleClickEventArgs)
   in DevExpress.Xpf.Grid.RowDoubleClickEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   in System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   in System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   in DevExpress.Xpf.Grid.TableView.DevExpress.Xpf.Grid.ITableView.RaiseRowDoubleClickEvent(DevExpress.Xpf.Grid.Native.ITableViewHitInfo, System.Windows.Input.MouseButton)
   in DevExpress.Xpf.Grid.Native.TableViewBehavior.OnDoubleClick(System.Windows.Input.MouseButtonEventArgs)
   in DevExpress.Xpf.Grid.DataViewBase.OnPreviewMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs)
   in System.Windows.Controls.Control.HandleDoubleClick(System.Object, System.Windows.Input.MouseButtonEventArgs)
   in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   in System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
   in System.Windows.UIElement.OnPreviewMouseDownThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   in System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   in System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   in System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   in System.Windows.Input.InputManager.ProcessStagingArea()
   in System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   in System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   in System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
   in System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
   in System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   in MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   in MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   in System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   in System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   in System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   in MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   in MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   in System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   in System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   in System.Windows.Application.RunDispatcher(System.Object)
   in System.Windows.Application.RunInternal(System.Windows.Window)
   in System.Windows.Application.Run(System.Windows.Window)
   in OM.App.Main()

To reproduce

Upgrade version from 6.0.2 to 6.1.1
WPF Application Framework 4.8 + Entity Framework 6.5.1
Microsoft Windows 10 22H2 (build SO 19045.6216)
MSSQL (13.00.4259)

Activity

  1. self-assigned this
    on Sep 3, 2025
  2. paulmedynski commented on Sep 3, 2025

    @paulmedynski
    Contributor

    Hi @EcTomBot,

    I'm unable to reproduce this issue against .NET 9.0 or .NET Framework 4.8.1, using a variety of locales.

    Could you provide the following information:

    • .NET SDK - What SDK are you using to build.
    • Target Framework - What frameworks are you targeting, for example .NET 9.0, .NET Framework 4.8.1, etc?
    • .NET Runtime - What runtime is running the app.
    • Locale - What locale/culture are you running in, for example Italian (it_IT)?

    It would also be helpful for you to provide a minimal project that reproduces the issue.

  3. EcTomBot commented on Sep 4, 2025

    @EcTomBot
    Author

    Hi @paulmedynski

    With the following .net Framework 4.8 console application the problem occurs
    ConsoleApp48.zip

    The application is build by Visual Studio 2022 on Windows 11 64-bit

    On my PC is installed following .net SDK and runtime

    C:\Program Files\dotnet>dotnet --list-sdks
    3.1.426 [C:\Program Files\dotnet\sdk]
    5.0.214 [C:\Program Files\dotnet\sdk]
    5.0.303 [C:\Program Files\dotnet\sdk]
    5.0.408 [C:\Program Files\dotnet\sdk]
    9.0.304 [C:\Program Files\dotnet\sdk]

    C:\Program Files\dotnet>dotnet --list-runtimes
    Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

    Microsoft .NET SDK 9.0.304 (x64) from Visual Studio ARP\Machine\X64{77D50DBE-C9D9-4EBF-9C54-172ACA940375} 9.3.425.36819
    Microsoft .NET SDK 5.0.214 (x64) Microsoft.DotNet.SDK.5 5.0.214 5.0.408 winget
    Microsoft .NET SDK 5.0.408 (x64) Microsoft.DotNet.SDK.5 5.0.408 winget
    Microsoft .NET SDK 5.0.303 (x64) ARP\Machine\X86{b447173e-28f0-40ae-b0c8-15b9c0a1ad4b} 5.3.321.37723
    Microsoft .NET Core Runtime - 2.1.30 (x64) Microsoft.DotNet.Runtime.3_1 < 3.1.25 3.1.32 winget
    Microsoft .NET Core SDK 3.1.426 (x64) Microsoft.DotNet.SDK.3_1 3.1.426 winget
    Microsoft .Net Native Framework Package 2.1 MSIX\Microsoft.NET.Native.Framework.2.1_2.1.27427.0_x64__8wekyb3d8bbwe 2.1.27427.0
    Microsoft .Net Native Framework Package 2.1 MSIX\Microsoft.NET.Native.Framework.2.1_2.1.27427.0_x86__8wekyb3d8bbwe 2.1.27427.0
    Microsoft .Net Native Runtime Package 2.1 MSIX\Microsoft.NET.Native.Runtime.2.1_2.1.26424.0_x64__8wekyb3d8bbwe 2.1.26424.0
    Microsoft .Net Native Runtime Package 2.1 MSIX\Microsoft.NET.Native.Runtime.2.1_2.1.26424.0_x86__8wekyb3d8bbwe 2.1.26424.0
    Microsoft .Net Native Framework Package 1.7 MSIX\Microsoft.NET.Native.Framework.1.7_1.7.27413.0_x86__8wekyb3d8bbwe 1.7.27413.0
    Microsoft .Net Native Framework Package 1.7 MSIX\Microsoft.NET.Native.Framework.1.7_1.7.27413.0_x64__8wekyb3d8bbwe 1.7.27413.0
    Microsoft .Net Native Runtime Package 2.2 MSIX\Microsoft.NET.Native.Runtime.2.2_2.2.28604.0_x64__8wekyb3d8bbwe 2.2.28604.0
    Microsoft .Net Native Runtime Package 2.2 MSIX\Microsoft.NET.Native.Runtime.2.2_2.2.28604.0_x86__8wekyb3d8bbwe 2.2.28604.0
    Microsoft .Net Native Runtime Package 1.7 MSIX\Microsoft.NET.Native.Runtime.1.7_1.7.27422.0_x86__8wekyb3d8bbwe 1.7.27422.0
    Microsoft .Net Native Runtime Package 1.7 MSIX\Microsoft.NET.Native.Runtime.1.7_1.7.27422.0_x64__8wekyb3d8bbwe 1.7.27422.0
    Microsoft .Net Native Framework Package 2.2 MSIX\Microsoft.NET.Native.Framework.2.2_2.2.29512.0_x86__8wekyb3d8bbwe 2.2.29512.0
    Microsoft .Net Native Framework Package 2.2 MSIX\Microsoft.NET.Native.Framework.2.2_2.2.29512.0_x64__8wekyb3d8bbwe 2.2.29512.0
    Microsoft .Net Native Runtime Package 1.4 MSIX\Microsoft.NET.Native.Runtime.1.4_1.4.24201.0_x86__8wekyb3d8bbwe 1.4.24201.0
    Microsoft .Net Native Runtime Package 1.4 MSIX\Microsoft.NET.Native.Runtime.1.4_1.4.24201.0_x64__8wekyb3d8bbwe 1.4.24201.0
    Microsoft .Net Native Framework Package 1.3 MSIX\Microsoft.NET.Native.Framework.1.3_1.3.24211.0_x64__8wekyb3d8bbwe 1.3.24211.0
    Microsoft .Net Native Framework Package 1.3 MSIX\Microsoft.NET.Native.Framework.1.3_1.3.24211.0_x86__8wekyb3d8bbwe 1.3.24211.0
    Microsoft Windows Desktop Runtime - 3.1.32 (x86) Microsoft.DotNet.DesktopRuntime.3_1 3.1.32 winget
    Microsoft Windows Desktop Runtime - 5.0.17 (x86) Microsoft.DotNet.DesktopRuntime.5 5.0.17 winget
    Microsoft Windows Desktop Runtime - 6.0.36 (x86) Microsoft.DotNet.DesktopRuntime.6 6.0.36 winget

    On the client PC, the application displays the following error:
    Il contatore di prestazioni richiesto non è un contatore personalizzato. Deve essere inizializzato in sola lettura. in System.Diagnostics.PerformanceCounter.InitializeImpl() in System.Diagnostics.PerformanceCounter.Increment() in Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) in Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) in Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value) in Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential) in Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in ConsoleApp48.Program.Main(String[] args) in C:\Users\Tomaso\source\repos\ConsoleApp48\ConsoleApp48\Program.cs:riga 16

    And it has these characteristics:


    Processore AMD A8 PRO-7600B R7, 10 Compute Cores 4C+6G 3.10 GHz
    RAM installata 8,00 GB (7,70 GB utilizzabile)
    Archiviazione 238 GB SSD SanDisk SD8SB8U-256G-1006
    Scheda grafica AMD Radeon(TM) R7 Graphics (236 MB)
    Tipo sistema Sistema operativo a 64 bit, processore basato su x64

    Windows 10 Pro
    Versione 22H2
    Data installazione: ‎13/‎01/‎2021
    Build sistema operativo 19045.6282

    .Net Runtime

    2.0.50727.4927 Service Pack 2
    3.0.30729.4926 Service Pack 2
    3.5.30729.4926 Service Pack 1
    4.0.0.0
    4.8.09037

    Thanks

  4. ChristCay commented on Sep 5, 2025

    @ChristCay

    Hello, I just had the same problem on one of my servers. This server don't have performance counters ".NET CLR Data", no problem on the other servers that have this counter's category. Check on your server in perfmon.msc.
    Regards

  5. EcTomBot commented on Sep 8, 2025

    @EcTomBot
    Author

    Thanks, Christ
    As you suggested, loading the following .Net Performance Counters solved the problem:

    lodctr "C:\Windows\INF.NET CLR Data_DataPerfCounters.ini"
    lodctr "C:\Windows\INF.NET CLR Networking_Networkingperfcounters_v2.ini"
    lodctr "C:\Windows\INF.NET CLR Networking 4.0.0.0_Networkingperfcounters.ini"
    lodctr "C:\Windows\INF.NET Data Provider for Oracle_DataOracleClientPerfCounters_shared12_neutral.ini"
    lodctr "C:\Windows\INF.NET Data Provider for SqlServer_dataperfcounters_shared12_neutral.ini"
    lodctr "C:\Windows\INF.NET Memory Cache 4.0\netmemorycache.ini"
    lodctr "C:\Windows\INF.NETFramework\corperfmonsymbols.ini"

    You may not need to upload them all, but just to be safe... :-)

  6. theprev commented on Sep 10, 2025

    @theprev

    I hope that it will be fixed, adding the performance counter is not the right solution ....

  7. RichardD2 commented on Sep 16, 2025

    @RichardD2

    Just run into the same issue on a 2016 server. The workaround from EcTomBot worked, after I restored the path separators that seems to have been stripped out by the Markdown processing:

    lodctr "C:\Windows\INF\.NET CLR Data\_DataPerfCounters.ini"
    lodctr "C:\Windows\INF\.NET CLR Networking\_Networkingperfcounters_v2.ini"
    lodctr "C:\Windows\INF\.NET CLR Networking 4.0.0.0\_Networkingperfcounters.ini"
    lodctr "C:\Windows\INF\.NET Data Provider for Oracle\_DataOracleClientPerfCounters_shared12_neutral.ini"
    lodctr "C:\Windows\INF\.NET Data Provider for SqlServer\_dataperfcounters_shared12_neutral.ini"
    lodctr "C:\Windows\INF\.NET Memory Cache 4.0\netmemorycache.ini"
    lodctr "C:\Windows\INF\.NETFramework\corperfmonsymbols.ini"
    
  8. mbursill commented on Sep 16, 2025

    @mbursill

    We also encountered this issue with Microsoft.Data.SqlClient 6.1.1. One of our servers was missing performance counters, which resulted in the error:

    The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.

    This was for a .NET Framework 4.8 MVC 5 app. We apply Entity Framework 6 migrations using EF6.exe, and that's when we'd receive the error.

    We were able to resolve the block by installing the counters. Specifically the .NET Data Provider for SqlServer was the one needed to unblocked.

    However, we later had an outage with the error:

    Custom counters file view is out of memory.

    We run several tenants (IIS sites) of a multi-tenant app across many shared pools, and are required to run them at 32bit to save on resources. We attempted to bump filemappingsize to the max allowed of 33,554,432 bytes (https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/trace-debug/performancecounters-element), however the error would return.

    In the end we rolled back to Microsoft.Data.SqlClient 6.0.2.

  9. dziedrius commented on Sep 19, 2025

    @dziedrius

    Having the same problem here, was chasing the problem for two days and pulling my hair (completely bold now).

    It was on our lab server, so we thought we have too many app instances going and that causing the issue, but even after reducing .net processes count, we were facing same issue:

    System.InvalidOperationException: Custom counters file view is out of memory.
    at System.Diagnostics.SharedPerformanceCounter.CalculateMemory(Int32 oldOffset, Int32 totalSize, Int32& alignmentAdjustment)
    at System.Diagnostics.SharedPerformanceCounter.CreateInstance(CategoryEntry* categoryPointer, Int32 instanceNameHashCode, String instanceName, PerformanceCounterInstanceLifetime lifetime)
    at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
    at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
    at System.Diagnostics.PerformanceCounter.InitializeImpl()
    at System.Diagnostics.PerformanceCounter.Increment()
    at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
    at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
    at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)

    The worst thing - it is random, we were reproducing it often, but not every time (again, we run ~200 .net processes on that server, so that might contribute a lot to the problem).

    Tried to add registry keys to increase file mapping size, settings to machine.config, nothing helped, this was very very confusing.

    I've tried to look into the code, but there's too much stuff going on to understand it quickly, even for troubleshooting purposes.
    Also using Windows SQL 2016 server.

  10. dziedrius commented on Sep 26, 2025

    @dziedrius

    Any idea when this fix will be released?

    Also I've tried workaround mentioned in pull request:

    lodctr "C:\Windows\INF\.NET Data Provider for SqlServer\_dataperfcounters_shared12_neutral.ini"
    

    When I was running it, lodctr said that this is already loaded - so theoretically I should not have seen the issue.
    I've unloaded and loaded again, but issue still randomly reappears 🤷.
    Also I did quite a bit of digging to make sure that we're not actually overflowing file size allocated to perfcounters, from captured data it seems that we're not and not even close to limits.

  11. edwardneal commented on Oct 2, 2025

    @edwardneal
    Contributor

    I'm not sure when the next 6.1.x release date is, but the PR only mentioned the top-level issue because that was the only one which I could reliably reproduce.

    The PR ensured that performance counters which threw an InvalidOperationException when being initialized would never be used (as per the v6.0.x behaviour.) I expect this'll fix your issue - you saw an InvalidOperationException in an unexpected place because these were escaping, and PerformanceCounter was trying to initialize itself on the next use.

    If you grab the artifacts from the porting PR's CI run, you should be able to re-test in the interim. These are cleaned up every month, so probably won't be available after 23rd October.

  12. dziedrius commented on Oct 3, 2025

    @dziedrius

    Eh, it is marked as P3, but in general it is crashing apps for us for no clear reason.
    Downgraded to 6.0.2, can't wait anymore, using version from CI is not an option for bureaucratic reasons.

    It was not an easy downgrade, because we already started to use vector parameters, so needed to do nasty workarounds, as in 6.0.2 there's no vector types yet.

  13. added this to the 6.1.2 milestone on Oct 3, 2025
  14. paulmedynski commented on Oct 3, 2025

    @paulmedynski
    Contributor

    This will be fixed with 6.1.2, which we're hoping to release today. We missed associating PR #3629 here earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Regression 💥Issues that are regressions introduced from earlier PRs.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions