Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Author: ErcanOPAK

Asp.Net Core / C#

Request Body Can Only Be Read Once

- 19.12.25 - ErcanOPAK comment on Request Body Can Only Be Read Once

Middleware reading body breaks controllers. ✅ Fix Enable buffering: context.Request.EnableBuffering(); Then rewind stream.

Read More
Asp.Net Core / C#

Scoped Services Inside Singleton = Time Bomb

- 19.12.25 - ErcanOPAK comment on Scoped Services Inside Singleton = Time Bomb

public class MySingleton { public MySingleton(MyScopedService s) { } } ❌ Problem Captures first request scope forever Causes stale data & memory leaks ✅ Fix Use IServiceScopeFactory.

Read More
SQL

Implicit Data Type Conversion Breaks Index Usage

- 19.12.25 - ErcanOPAK comment on Implicit Data Type Conversion Breaks Index Usage

WHERE UserId = ‘123’ Column is INT. ❌ Result Index ignored Full scan ✅ Fix Match types exactly.

Read More
SQL

Why MERGE Can Corrupt Data Under Concurrency

- 19.12.25 | 19.12.25 - ErcanOPAK comment on Why MERGE Can Corrupt Data Under Concurrency

MERGE looks elegant… but has known race issues. ❌ Risks Duplicate inserts Missed updates Hard-to-reproduce bugs ✅ Safer Pattern Explicit UPDATE + INSERT with transaction.

Read More
C#

Expression Trees Can Kill Startup Time

- 19.12.25 - ErcanOPAK comment on Expression Trees Can Kill Startup Time

Heavy use of expression compilation: Expression<Func<T, bool>> ❌ Cost JIT + dynamic method generation Slow cold starts ✅ Fix Cache compiled expressions aggressively.

Read More
C#

Why lock(this) Can Deadlock Your Entire App

- 19.12.25 - ErcanOPAK comment on Why lock(this) Can Deadlock Your Entire App

lock(this) { // work } Hidden problem External code can lock the same instance Causes unpredictable deadlocks ✅ Correct private readonly object _lock = new(); lock (_lock) { }  

Read More
C#

GC.AllocateUninitializedArray — Faster Arrays With a Catch

- 19.12.25 - ErcanOPAK comment on GC.AllocateUninitializedArray — Faster Arrays With a Catch

GC.AllocateUninitializedArray — Faster Arrays With a Catch Why it’s fast Skips zero-initialization Reduces CPU cycles ⚠ Danger Memory contains garbage values Must fully overwrite before use Use case High-performance serializers, buffers, pipelines.

Read More
Visual Studio

Solution Loads Slowly — Roslyn Cache Corruption

- 17.12.25 - ErcanOPAK comment on Solution Loads Slowly — Roslyn Cache Corruption

VS silently rebuilds analyzers. ✅ Fix Delete: %LOCALAPPDATA%\Microsoft\VisualStudio\17.* Reopen solution → instant load.

Read More
Wordpress

WordPress Slow Even With Cache — Autoloaded Options

- 17.12.25 - ErcanOPAK comment on WordPress Slow Even With Cache — Autoloaded Options

Huge autoload rows load on every request. ✅ Fix Audit: SELECT * FROM wp_options WHERE autoload=’yes’; Disable unused entries.

Read More
Windows

High RAM Usage With Nothing Open

- 17.12.25 - ErcanOPAK comment on High RAM Usage With Nothing Open

Cause: Memory Compression. Windows compresses memory instead of freeing it. ✅ Tip High usage ≠ problem unless paging starts.

Read More
Windows

Windows 11 Defender Slowing Down Builds

- 17.12.25 - ErcanOPAK comment on Windows 11 Defender Slowing Down Builds

Real-time scanning kills compile speed. ✅ Fix Exclude: bin/ obj/ build output folders

Read More
Ajax / JavaScript

CORS Errors That Are NOT CORS Errors

- 17.12.25 - ErcanOPAK comment on CORS Errors That Are NOT CORS Errors

Most “CORS issues” are actually: 401 responses Missing headers Redirects ✅ Debug Tip Check Network → Response headers, not console.

Read More
JavaScript

Event Listeners Causing Memory Leaks

- 17.12.25 - ErcanOPAK comment on Event Listeners Causing Memory Leaks

Detached DOM nodes still hold listeners. ❌ Problem element.addEventListener(…) ✅ Fix Remove listeners explicitly or use { once: true }.

Read More
HTML

input type=”number” Breaks Mobile UX

- 17.12.25 - ErcanOPAK comment on input type=”number” Breaks Mobile UX

Mobile keyboards behave inconsistently. ✅ Better <input inputmode=”numeric” pattern=”[0-9]*”> Result Better mobile keyboards Fewer validation issues

Read More
CSS

will-change Can Make Performance Worse

- 17.12.25 - ErcanOPAK comment on will-change Can Make Performance Worse

will-change: transform; ❌ Overuse causes: GPU memory pressure Slower rendering ✅ Rule Apply only shortly before animation, remove after.

Read More
Asp.Net Core

Model Binding Is Slower Than You Think

- 17.12.25 - ErcanOPAK comment on Model Binding Is Slower Than You Think

Large request models cost CPU. ✅ Optimization Use [FromBody] DTOs instead of giant domain models. Why Less reflection Faster deserialization Cleaner APIs

Read More
Asp.Net Core

IOptionsSnapshot vs IOptionsMonitor — Subtle but Critical

- 17.12.25 - ErcanOPAK comment on IOptionsSnapshot vs IOptionsMonitor — Subtle but Critical

Wrong choice causes stale configs or memory leaks. IOptionsSnapshot → per request IOptionsMonitor → real-time updates ✅ Rule Use Monitor only if config changes at runtime.

Read More
SQL

Why NVARCHAR(MAX) Can Destroy Query Plans

- 17.12.25 - ErcanOPAK comment on Why NVARCHAR(MAX) Can Destroy Query Plans

Using NVARCHAR(MAX) everywhere is tempting. ❌ Hidden cost Prevents index usage Breaks memory grants ✅ Rule Use fixed lengths when possible: NVARCHAR(255)  

Read More
SQL

DATEDIFF in WHERE Clause Disables Indexes

- 17.12.25 - ErcanOPAK comment on DATEDIFF in WHERE Clause Disables Indexes

This looks innocent: WHERE DATEDIFF(day, CreatedAt, GETDATE()) = 0 ❌ Why it’s bad Forces full scan Index becomes useless ✅ Fix WHERE CreatedAt >= CAST(GETDATE() AS date)  

Read More
C#

Equals() Without GetHashCode() Breaks HashSets

- 17.12.25 - ErcanOPAK comment on Equals() Without GetHashCode() Breaks HashSets

Overriding only Equals() is a bug factory. public override bool Equals(object obj) { … } ❌ Missing: public override int GetHashCode() { … } Result HashSet duplicates Dictionary lookups fail silently

Read More
C#

Why Dictionary Suddenly Becomes Slow

- 17.12.25 - ErcanOPAK comment on Why Dictionary Suddenly Becomes Slow

The hidden killer: rehashing. When capacity grows, the dictionary reallocates everything. ✅ Fix Always pre-size: var dict = new Dictionary<int, User>(expectedCount); Real impact Eliminates random latency spikes Crucial in hot paths

Read More
C#

Span — The Secret Weapon for Zero-Allocation Code

- 17.12.25 - ErcanOPAK comment on Span — The Secret Weapon for Zero-Allocation Code

Most high-performance .NET code avoids allocations entirely. Span<char> buffer = stackalloc char[64]; Why this matters Zero GC pressure Massive performance boost in parsing & serialization Used heavily inside .NET itself ⚠ Cannot escape the method scope.

Read More
Visual Studio

Breakpoints Not Hit — Wrong Startup Project

- 17.12.25 - ErcanOPAK comment on Breakpoints Not Hit — Wrong Startup Project

Multi-project solutions bite hard. ✅ Fix Right-click correct project → Set as Startup Project

Read More
PHP

WordPress Images Killing Performance — Missing Sizes

- 17.12.25 - ErcanOPAK comment on WordPress Images Killing Performance — Missing Sizes

Uploading huge images without resizing is deadly. ✅ Fix Always use: the_post_thumbnail(‘medium_large’);  

Read More
Windows

Background Apps Draining Laptop Battery

- 17.12.25 - ErcanOPAK comment on Background Apps Draining Laptop Battery

Many apps run unseen. ✅ Fix Settings → Apps → Startup → Disable unused apps

Read More
Windows

Windows 11 Sluggish UI — Animation Overhead

- 17.12.25 - ErcanOPAK comment on Windows 11 Sluggish UI — Animation Overhead

Animations cost GPU time. ✅ Fix Settings → Accessibility → Visual Effects → Disable animations

Read More
Ajax / JavaScript

AJAX Requests Canceled on Page Navigation

- 17.12.25 - ErcanOPAK comment on AJAX Requests Canceled on Page Navigation

Requests silently stop. 🧠 Reason Browser cancels in-flight requests. ✅ Fix Use navigator.sendBeacon() for critical logs.

Read More
JavaScript

Floating Point Math Is Lying to You

- 17.12.25 - ErcanOPAK comment on Floating Point Math Is Lying to You

0.1 + 0.2 === 0.3 // false ✅ Fix Use rounding: Number((0.1 + 0.2).toFixed(2))  

Read More
HTML

- 17.12.25 - ErcanOPAK comment on

Inside forms, this causes accidental submits. ❌ <button>Click</button> ✅ Fix <button type=”button”>Click</button>  

Read More
CSS

overflow-x: hidden Is Not a Layout Fix

- 17.12.25 - ErcanOPAK comment on overflow-x: hidden Is Not a Layout Fix

Using this hides bugs instead of fixing them. ✅ Proper Fix Identify overflowing element Fix width or flex behavior

Read More
Page 53 of 69
« Previous 1 … 48 49 50 51 52 53 54 55 56 57 58 … 69 Next »

Posts navigation

Older posts
Newer posts
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com