Haziran 30, 2022

System.Text.Json.JsonException hatası - cycle or if the object depth is larger than the maximum allowed depth of 32.

 Eğer .net'te aşağıdaki hatayı alıyorsanız;

"A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32."

Startup.cs dosyanızda yer alan ConfigureServices metoduna aşağıdaki kodu ekleyin: 


 services.AddControllers()
.AddNewtonsoftJson(opt=>opt.SerializerSettings
.ReferenceLoopHandling=ReferenceLoopHandling.Ignore);           


Tabi eklemeden önce nuget pmden Newtonsoftson paketini projenize yükleyin. 

Haziran 20, 2022

React + .NET API CORS ayarları"

.NET ile hazırladığınız bir API'den react ile veri almaya çalışırken aşağıdaki hatayı alıyorsanız:

"'Access to fetch at '...' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.'"

startup.cs'de ConfigureServices altına;

 services.AddCors();

ve Configure'da yer alan app.UseRouting();altına;

    app.UseCors(opt =>
            {
                opt.AllowAnyHeader().AllowAnyMethod()
                .WithOrigins("http://localhost:3000");

            });

kodlarını yazmanız yeterli olacaktır. 

System.Text.Json.JsonException hatası - cycle or if the object depth is larger than the maximum allowed depth of 32.

 Eğer .net'te aşağıdaki hatayı alıyorsanız; " A possible object cycle was detected which is not supported. This can either be due t...