csharp Errors

132 error patterns

csharp3 fixes

AOT unsupported type usage

Type '.*' is not supported by the AOT compiler

  • Replace with AOT-compatible type
  • Add [DynamicallyAccessedMembers] attribute
csharp3 fixes

Trimming unsafe code detected

Trim analysis warning IL2026.*RequiresUnreferencedCode

  • Add [UnconditionalSuppressMessage]
  • Replace reflection with source generators
csharp3 fixes

Minimal API DI failure

No service for type '.*' has been registered

  • Register service in Program.cs
  • Check service lifetime
csharp3 fixes

Minimal API body binding failure

Failed to read parameter.*from the request body

  • Add [FromBody] attribute
  • Ensure Content-Type is application/json
csharp3 fixes

JSON property name collision

JSON property name for '.*' collides with another

  • Use [JsonPropertyName]
  • Rename conflicting properties
csharp3 fixes

JSON deserialization type mismatch

JSON value could not be converted to

  • Add custom JsonConverter
  • Match JSON value to CLR type
csharp3 fixes

Service activation missing dependency

Unable to resolve service.*while attempting to activate

  • Register all dependencies
  • Check for circular dependencies
csharp3 fixes

Blazor component not found

Cannot find component type '.*'

  • Add @using directive
  • Register in _Imports.razor
csharp3 fixes

Blazor incompatible render mode

Render mode '.*' is not compatible with the parent

  • Match child render mode to parent
  • Use consistent InteractiveServer/WebAssembly
csharp3 fixes

Blazor circuit disconnected

circuit.*has been disconnected

  • Implement reconnection handler
  • Add CircuitHandler service
csharp3 fixes

Blazor JS interop after disconnect

JavaScript interop calls cannot be issued

  • Check CircuitState before JS interop
  • Wrap in try-catch for JSDisconnectedException
csharp3 fixes

Blazor EditForm missing model

EditForm requires either a Model or an EditContext

  • Provide Model parameter
  • Create EditContext manually
csharp3 fixes

Blazor event handler not found

no event handler.*for this event

  • Ensure @on* handler method exists
  • Check for typos in callback name
csharp3 fixes

Blazor JS function not found

Could not find '.*' in 'window'

  • Ensure JS file loaded before interop
  • Register JS module with correct path
csharp3 fixes

Blazor cascading parameter missing

Cannot provide a value for property.*no cascading parameter

  • Wrap tree with CascadingValue
  • Add [SupplyParameterFromQuery]
csharp3 fixes

EF Core duplicate key violation

Cannot insert duplicate key

  • Check for existing entity before insert
  • Use AddOrUpdate pattern
csharp3 fixes

EF Core missing primary key

entity type '.*' requires a primary key

  • Add [Key] attribute
  • Configure HasKey() in OnModelCreating
csharp3 fixes

EF Core navigation not configured

not a navigation property of entity type

  • Configure relationship in OnModelCreating
  • Add navigation property with FK
csharp3 fixes

EF Core 8 complex type with key

Complex type.*cannot have a key

  • Remove [Key] from complex type
  • Use ComplexProperty() without key
csharp3 fixes

EF Core 8 complex type as entity

Complex type '.*' cannot be used as an entity

  • Use ComplexProperty<T>() configuration
  • Remove DbSet<T> for complex types
csharp3 fixes

EF Core unmapped property

Property '.*' on entity type '.*' is unmapped

  • Add [NotMapped] attribute
  • Configure Ignore() in OnModelCreating
csharp3 fixes

EF Core property vs navigation conflict

cannot be used as a property.*configured as a navigation

  • Separate FK from navigation property
  • Configure relationship explicitly
csharp3 fixes

EF Core TPH discriminator conflict

discriminator property.*cannot be mapped to a different column

  • Use HasDiscriminator() consistently
  • Use same discriminator column across hierarchy
csharp3 fixes

EF Core TPT missing table mapping

part of a hierarchy.*must also be mapped to a table

  • Add ToTable() for each derived type
  • Use UseTptMappingStrategy()
csharp3 fixes

EF Core compiled query stale

compiled query.*has become stale

  • Rebuild compiled query after model changes
  • Don't modify DbContext after compilation
csharp3 fixes

EF Core compiled query closure

Cannot create a compiled query.*closure

  • Pass parameters as method arguments
  • Use explicit parameter types
csharp3 fixes

SignalR unauthorized hub invocation

Failed to invoke '.*' because user is unauthorized

  • Add [Authorize] to hub/method
  • Pass JWT in connection query string
csharp3 fixes

SignalR send on disconnected connection

Connection.*is not in the Connected state

  • Check connection state before sending
  • Use WithAutomaticReconnect()
csharp3 fixes

SignalR connection aborted

connection was aborted.*SignalR

  • Increase KeepAliveInterval
  • Implement IHubLifetimeManager
csharp3 fixes

SignalR Redis backplane failure

RedisConnectionException.*SignalR backplane

  • Verify Redis connection string
  • Configure retry policy in Redis options
csharp3 fixes

gRPC deadline exceeded

StatusCode=.*DeadlineExceeded

  • Increase deadline in CallOptions
  • Optimize server processing time
csharp3 fixes

gRPC service unavailable

StatusCode=.*Unavailable.*failed to connect

  • Verify server running and port correct
  • Configure retry policy
csharp3 fixes

gRPC metadata after request started

Request headers must be sent.*gRPC

  • Set headers before calling RPC method
  • Use CallOptions for metadata
csharp3 fixes

gRPC call initialization error

Error starting gRPC call

  • Ensure HTTP/2 configured on channel
  • Check server proto service definition
csharp3 fixes

gRPC write to completed stream

stream has already been completed

  • Check stream completion before writing
  • Use CancellationToken for lifecycle
csharp3 fixes

MAUI XAML type resolution failure

Cannot resolve type.*MAUI

  • Add xmlns namespace declaration
  • Register handler with ConfigureMauiHandlers
csharp3 fixes

MAUI data binding property not found

property not found on.*MAUI|Binding.*property not found

  • Verify property name on BindingContext type
  • Implement INotifyPropertyChanged
csharp3 fixes

MAUI handler not registered

No handler.*registered for view

  • Register in ConfigureMauiHandlers
  • Create platform-specific handler
csharp3 fixes

MAUI platform-specific not supported

not supported on (iOS|Android|Windows|MacCatalyst)

  • Use #if ANDROID/IOS compilation
  • Check DeviceInfo.Platform
csharp3 fixes

Source generator no output

Source generator '.*' produced no output

  • Verify partial keyword on targets
  • Check Initialize registers correct syntax
csharp3 fixes

Source generator diagnostic error

SG\d+.*source generator

  • Check GeneratorDiagnostics for details
  • Verify SyntaxReceiver predicate
csharp3 fixes

Incremental generator pipeline failure

IncrementalGenerator.*pipeline.*failed

  • Ensure valid source text in RegisterSourceOutput
  • Check for null in transforms
csharp3 fixes

Source generator syntax receiver miss

SyntaxReceiver.*did not receive expected

  • Check OnVisitSyntaxNode SyntaxKind
  • Log candidate nodes for debugging
csharp3 fixes

AOT generic requires runtime codegen

IL3050.*generic.*requires runtime code generation

  • Use [DynamicallyAccessedMembers]
  • Pre-instantiate generics with rd.xml
csharp3 fixes

AOT missing method after publish

MissingMethodException.*not found.*PublishAot

  • Add [DynamicDependency] attribute
  • Configure TrimmerRootAssembly
csharp3 fixes

Reflection.Emit not available in AOT

Reflection\.Emit.*not supported.*AOT

  • Replace with source generators
  • Use compiled expressions
csharp3 fixes

Auth metadata without auth middleware

contains authorization metadata.*no authentication

  • Add UseAuthentication() before UseAuthorization()
  • Configure authentication scheme
csharp3 fixes

Minimal API ambiguous route

No route matches.*ambiguous

  • Add route constraints
  • Use specific HTTP method attributes
csharp3 fixes

Blazor streaming incompatible render mode

streaming rendering.*not supported.*render mode

  • Use [StreamRendering] only with Server mode
  • Remove from WebAssembly components
csharp3 fixes

EF Core 8 complex type with navigation

Complex type.*cannot contain navigation

  • Move navigation to owning entity
  • Use owned entity for relationships
csharp3 fixes

SignalR MessagePack serialization failure

MessagePack.*cannot serialize type

  • Add [MessagePackObject] and [Key] attributes
  • Register custom formatter
csharp3 fixes

SignalR hub method not accessible

Hub method '.*' is not accessible

  • Make hub method public
  • Remove [NonAction] conflict
csharp3 fixes

gRPC unimplemented method

StatusCode=.*Unimplemented

  • Implement method in service class
  • Regenerate proto stubs
csharp3 fixes

gRPC HTTP/2 not configured

HTTP/2.*not supported.*Kestrel

  • Set Protocols = Http2 in Kestrel
  • Use Http1AndHttp2 for mixed traffic
csharp3 fixes

MAUI UI operation from background thread

must be called from the UI thread|MainThread

  • Use MainThread.BeginInvokeOnMainThread()
  • Use Dispatcher.DispatchAsync()
csharp3 fixes

Service from disposed scope

IServiceProvider.*disposed.*scope

  • Don't capture scoped in singletons
  • Create new scope with IServiceScopeFactory
csharp3 fixes

Scoped service in singleton

Cannot consume scoped service.*from singleton

  • Inject IServiceScopeFactory into singleton
  • Change lifetime to singleton if stateless
csharp3 fixes

Blazor enhanced nav antiforgery missing

enhanced navigation.*antiforgery

  • Add @rendermode InteractiveServer
  • Include AntiforgeryToken in form
csharp3 fixes

EF Core IAsyncEnumerable cast error

Unable to cast.*IAsyncEnumerable

  • Use ToAsyncEnumerable() extension
  • Await ToListAsync() before casting
csharp3 fixes

EF Core client evaluation blocked

client.*evaluation.*not allowed

  • Rewrite to server-translatable LINQ
  • Call AsEnumerable() at right point
csharp3 fixes

EF Core duplicate tracking

is being tracked.*cannot track another.*same key

  • Use AsNoTracking() for read-only
  • Detach existing before attaching
csharp3 fixes

EF Core concurrency conflict

DbUpdateConcurrencyException.*affected 0 row

  • Reload entity and retry
  • Add [ConcurrencyCheck] or [Timestamp]
csharp3 fixes

EF Core table sharing conflict

Cannot use table '.*' for entity.*already used

  • Use ToTable() with different names
  • Configure table splitting with shared PK
csharp3 fixes

Source generator attribute not found

attribute '.*' not found in compilation

  • Add attribute to generator output
  • Reference containing assembly
csharp3 fixes

Blazor render batch too large

maximum batch size exceeded

  • Implement virtualization
  • Paginate data
csharp3 fixes

MAUI Shell route not registered

Shell.*route.*not registered

  • Register with Routing.RegisterRoute()
  • Use correct route pattern
csharp3 fixes

NativeAOT type not preserved

dynamically accessed.*not preserved

  • Add [DynamicallyAccessedMembers]
  • Include in rd.xml
csharp3 fixes

Blazor render mode wrong context

IComponentRenderMode.*not supported in this context

  • Move outside static rendering
  • Apply at page level
csharp3 fixes

gRPC channel used after shutdown

channel.*already shut down

  • Check channel state before calls
  • Implement channel lifecycle management
csharp3 fixes

SignalR send buffer overflow

send.*buffer.*full

  • Increase MaximumReceiveMessageSize
  • Implement backpressure with Channel<T>
csharp3 fixes

EF Core owned type shared

owned type.*cannot be shared between multiple owners

  • Create separate instances per owner
  • Use complex type for value semantics
csharp3 fixes

MAUI duplicate BindableProperty

BindableProperty.*already registered

  • Make field static readonly
  • Check base class definitions
csharp3 fixes

Minimal API TypedResults conversion

TypedResults.*cannot be converted

  • Use Results<T1,T2> union type
  • Use TypedResults.* consistently
csharp3 fixes

EF Core query filter cycle

query filter.*causes cycle

  • Use IgnoreQueryFilters() to break cycle
  • Restructure to avoid self-reference
csharp3 fixes

SignalR all transports failed

long polling.*transport.*fallback failed

  • Verify WebSocket support on server
  • Configure CORS for negotiation
csharp3 fixes

AOT MakeGenericType unsupported

MakeGenericType.*not supported

  • Pre-instantiate generics at compile time
  • Use source generator for concrete types
csharp3 fixes

Blazor component disposed in async

component.*disposed.*during async

  • Use CancellationToken from lifetime
  • Check IsDisposed before state update
csharp3 fixes

EF Core shadow property missing

shadow property.*not configured

  • Configure with Property<T>(name)
  • Access via EF.Property<T>()
csharp3 fixes

MAUI CollectionView no template

CollectionView.*ItemTemplate.*null

  • Set ItemTemplate with DataTemplate
  • Use ItemsLayout configuration
csharp3 fixes

gRPC reflection not enabled

server reflection.*not enabled

  • Add AddGrpcReflection()
  • Install Grpc.AspNetCore.Server.Reflection
csharp3 fixes

Incremental generator invalidation loop

incremental.*input changed.*re-run

  • Ensure value equality on pipeline values
  • Use record types for intermediates
csharp3 fixes

Blazor PersistComponentState unavailable

persist component state.*not available

  • Register PersistentComponentState
  • Use [SupplyParameterFromPersistentComponentState]
csharp3 fixes

Minimal API filter conflict

filter.*short-circuit.*conflict

  • Order filters correctly
  • Return Results.* to short-circuit
csharp3 fixes

AOT type initializer exception

type initializer.*threw.*AOT|TypeLoadException.*AOT

  • Move init out of static constructors
  • Use Lazy<T> for deferred init
csharp3 fixes

EF Core temporal table period missing

temporal table.*period.*not configured

  • Configure with .IsTemporal()
  • Set PeriodStart/PeriodEnd columns
csharp3 fixes

Blazor render mode changed after init

render mode.*cannot be changed after.*initialized

  • Set render mode before first render
  • Use static assignment at declaration
csharp3 fixes

SignalR parameter binding failure

hub.*method.*parameter.*cannot be bound

  • Ensure type is JSON-serializable
  • Match client arg types to signature
csharp3 fixes

gRPC proto import not found

proto file.*import.*not found

  • Add proto to Protobuf ItemGroup
  • Set ProtoRoot correctly
csharp3 fixes

MAUI page not registered in DI

MAUI.*page.*not registered

  • Register with AddTransient<MyPage>()
  • Register ViewModel in DI
csharp3 fixes

EF Core value converter null handling

value converter.*cannot convert.*null

  • Handle null in converter logic
  • Mark property as nullable
csharp3 fixes

AOT JSON unsupported type

JsonSerializer.*not supported.*type.*AOT

  • Add [JsonSerializable(typeof(T))]
  • Use source-generated JsonSerializerContext
csharp3 fixes

Blazor SectionOutlet not found

section.*outlet.*not found

  • Add SectionOutlet with matching name
  • Ensure name matches SectionContent
csharp3 fixes

SignalR invoke during reconnection

reconnecting.*cannot invoke

  • Queue messages during reconnection
  • Listen to Reconnecting events
csharp3 fixes

EF Core split query with projection

split query.*cannot be applied.*projection

  • Remove AsSplitQuery() with Select
  • Use single query for projections
csharp3 fixes

AOT method access restriction

method.*not accessible.*security.*AOT

  • Add [UnsafeAccessor] attribute
  • Use public API surface
csharp3 fixes

MAUI handler reuse conflict

handler.*already connected.*different virtual view

  • Create new handler per view
  • Disconnect before reassigning
csharp3 fixes

Blazor interactive root static render

root component.*cannot be rendered statically

  • Apply render mode at App level
  • Use @rendermode on declaration
csharp3 fixes

Source generator file not found

AdditionalText.*file not found

  • Add as AdditionalFiles in csproj
  • Verify path relative to project
csharp3 fixes

gRPC stream read timeout

stream.*read.*timed out.*gRPC

  • Set ReadTimeout on options
  • Implement heartbeat messages
csharp3 fixes

EF Core JSON column unsupported type

JSON column.*not supported for type

  • Use ToJson() with owned types only
  • Ensure parameterless constructor
csharp3 fixes

Event Store Concurrency Conflict

EventStore.*WrongExpectedVersion.*concurrency conflict

  • Reload aggregate and retry command
  • Use optimistic concurrency with expected version
csharp3 fixes

Event Store Projection Faulted

EventStore.*projection.*faulted.*checkpoint

  • Reset projection to last good checkpoint
  • Fix projection code causing the fault
csharp4 fixes

NullReferenceException: Object reference not set

System\.NullReferenceException.*Object reference not set to an instance of an object

  • Add null check before accessing the object: if (obj != null) { ... }
  • Use null-conditional operator: obj?.Property
csharp4 fixes

InvalidOperationException: Sequence contains no elements

InvalidOperationException.*Sequence contains no elements

  • Use FirstOrDefault() instead of First()
  • Use SingleOrDefault() instead of Single()
csharp4 fixes

InvalidOperationException: Collection modified during enumeration

InvalidOperationException.*Collection was modified.*enumeration

  • Call .ToList() before iterating: foreach (var item in list.ToList())
  • Use a for loop with reverse index when removing items
csharp4 fixes

ArgumentNullException: Value cannot be null

System\.ArgumentNullException.*Value cannot be null.*Parameter name: (\w+)

  • Ensure the argument is not null before passing it to the method
  • Add a guard clause: ArgumentNullException.ThrowIfNull(param)
csharp3 fixes

ArgumentException: Invalid argument value

System\.ArgumentException.*is not a valid value

  • Validate input before passing to method
  • Check enum values with Enum.IsDefined() before casting
csharp4 fixes

InvalidCastException: Unable to cast object

System\.InvalidCastException.*Unable to cast object of type '(.+)' to type '(.+)'

  • Use 'as' operator with null check instead of direct cast: var x = obj as TargetType
  • Use pattern matching: if (obj is TargetType typed) { ... }
csharp4 fixes

CS0103: Name does not exist in current context

error CS0103.*The name '(.+)' does not exist in the current context

  • Add the missing using directive for the namespace
  • Check for typos in the variable/method name
csharp4 fixes

CS0234: Type or namespace not found

error CS0234.*The type or namespace name '(.+)' does not exist in the namespace '(.+)'

  • Install the missing NuGet package: dotnet add package <PackageName>
  • Add a project reference: dotnet add reference <ProjectPath>
csharp4 fixes

CS1061: Type does not contain definition for member

error CS1061.*'(.+)' does not contain a definition for '(.+)'

  • Check for typos in the member name
  • Add the missing using directive for extension methods
csharp4 fixes

CS0029: Cannot implicitly convert type

error CS0029.*Cannot implicitly convert type '(.+)' to '(.+)'

  • Add an explicit cast: (TargetType)value
  • Use a conversion method: int.Parse(), ToString(), Convert.ToInt32()
csharp4 fixes

CS8600: Possible null to non-nullable conversion

warning CS8600.*Converting null literal or possible null value to non-nullable type

  • Declare the variable as nullable: string? result = ...
  • Add a null check or guard before assignment
csharp4 fixes

CS8602: Dereference of possibly null reference

warning CS8602.*Dereference of a possibly null reference

  • Add a null check before dereferencing: if (obj != null) obj.Method()
  • Use null-conditional operator: obj?.Method()
csharp4 fixes

CS8604: Possible null reference argument

warning CS8604.*Possible null reference argument for parameter

  • Add a null check before passing the argument
  • Use the ?? operator to provide a fallback: param ?? defaultValue
csharp4 fixes

NETSDK1045: SDK does not support target framework

NETSDK1045.*The current \.NET SDK does not support targeting

  • Install the required .NET SDK version from https://dotnet.microsoft.com/download
  • Update global.json to use an installed SDK version
csharp4 fixes

NETSDK1005: Target framework version mismatch

NETSDK1005.*Project .+ targets '(.+)'.*current SDK

  • Install the matching .NET SDK for the target framework
  • Change TargetFramework in .csproj to match installed SDK
csharp4 fixes

EF Core: Migration already applied or database up to date

No migrations were applied.*database is already up to date|The migration '(.+)' has already been applied

  • Run 'dotnet ef migrations list' to check applied migrations
  • Create a new migration: dotnet ef migrations add <Name>
csharp4 fixes

EF Core / SQL: Connection string or database access error

Cannot open database|A network-related or instance-specific error|Login failed for user

  • Verify ConnectionStrings section in appsettings.json
  • Ensure the database server is running and accessible
csharp4 fixes

ASP.NET Core DI: Service not registered

InvalidOperationException.*No service for type '(.+)' has been registered|Unable to resolve service for type '(.+)'

  • Register the service in Program.cs: builder.Services.AddScoped<IService, Service>()
  • Check that the interface and implementation match the registered types
csharp4 fixes

ASP.NET Core: CORS policy blocking requests

Access to fetch.*blocked by CORS|has been blocked by CORS policy|No 'Access-Control-Allow-Origin'

  • Add CORS in Program.cs: builder.Services.AddCors() with a policy allowing the origin
  • Call app.UseCors("policyName") BEFORE app.UseAuthorization()
csharp4 fixes

ASP.NET Core: 404 Not Found / Route not matched

StatusCode.*404|NotFound|No route matches|endpoint routing.*did not match

  • Verify the [Route] and [Http*] attributes on the controller/action
  • Ensure app.MapControllers() is called in Program.cs
csharp4 fixes

HttpClient: SSL/TLS certificate error

The SSL connection could not be established|AuthenticationException.*remote certificate

  • For development, bypass with HttpClientHandler.ServerCertificateCustomValidationCallback
  • Install/trust the development certificate: dotnet dev-certs https --trust
csharp4 fixes

HttpClient: Request timeout

TaskCanceledException.*A task was canceled|HttpRequestException.*request timed out|The request was canceled due to.*timeout

  • Increase HttpClient.Timeout: client.Timeout = TimeSpan.FromSeconds(120)
  • Use CancellationTokenSource with a longer timeout
csharp4 fixes

HttpClient: Connection refused

HttpRequestException.*Connection refused|No connection could be made|actively refused

  • Verify the target service is running on the expected host:port
  • Check the base URL in configuration (appsettings/environment variable)
csharp4 fixes

JSON Serialization: Object cycle detected

JsonException.*cycle.*detected|A possible object cycle was detected

  • Add ReferenceHandler.IgnoreCycles: options.ReferenceHandler = ReferenceHandler.IgnoreCycles
  • Use [JsonIgnore] on navigation properties that cause circular references
csharp4 fixes

JSON Deserialization: Type conversion error

JsonException.*could not be converted|Cannot deserialize|The JSON value could not be converted to

  • Check that JSON property types match C# model types (e.g., string vs int)
  • Add JsonNumberHandling.AllowReadingFromString for numeric strings
csharp4 fixes

MSB4019: Imported project not found

error MSB4019.*The imported project.*was not found

  • Restore NuGet packages: dotnet restore
  • Install the required workload: dotnet workload install <workload>
csharp4 fixes

NU1101/NU1102: NuGet package not found

error NU1101.*Unable to find package|NU1102.*Unable to find package.*in any source

  • Check the package name for typos
  • Add the correct NuGet source in nuget.config
csharp4 fixes

EF Core: DbContext already disposed

InvalidOperationException.*DbContext.*disposed|Cannot access a disposed context|disposed object.*DbContext

  • Don't capture DbContext in a background task — inject IDbContextFactory<T> instead
  • Register DbContext as Scoped (default), not Transient or Singleton
csharp4 fixes

ASP.NET Core: Middleware order incorrect

InvalidOperationException.*Middleware.*must be added before|UseRouting.*must be added before UseEndpoints|UseAuthentication.*must be called before UseAuthorization

  • Follow the correct middleware order: UseRouting → UseAuthentication → UseAuthorization → MapControllers
  • Place UseCors() before UseAuthorization()
csharp4 fixes

MSB3027: File locked by another process during build

error MSB3027.*Could not copy.*being used by another process|IOException.*used by another process

  • Stop the running application (dotnet run / IIS Express / kestrel)
  • Close any file handles — check with Process Explorer or 'handle.exe'