riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
743 stars 97 forks source link

Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0. #1040

Closed daltinkurt closed 3 years ago

daltinkurt commented 3 years ago

I upgraded to net5 and also latest dotvvm nuget package. I get this error after click the button.

Is this error releated to me or you? :)

stack trace:

JObject Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
JObject Newtonsoft.Json.Linq.JObject.Parse(string json, JsonLoadSettings settings)
JObject Newtonsoft.Json.Linq.JObject.Parse(string json)
void DotVVM.Framework.ViewModel.Serialization.DefaultViewModelSerializer.PopulateViewModel(IDotvvmRequestContext context, string serializedPostData)
async Task DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequestCore(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequestCore(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmPresenter.ProcessRequest(IDotvvmRequestContext context)
async Task<bool> DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)
async Task<bool> DotVVM.Framework.Hosting.Middlewares.DotvvmRoutingMiddleware.Handle(IDotvvmRequestContext context)
async Task DotVVM.Framework.Hosting.DotvvmMiddleware.Invoke(HttpContext context)
async Task DotVVM.Framework.Hosting.Middlewares.DotvvmErrorPageMiddleware.Invoke(HttpContext context)

DotVVM.AspNetCore 3.0.4 .NET 5.0.6

request header:

:authority: crm.megagen.com.tr
:method: POST
:path: /Member/Login
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7
content-length: 729
content-type: application/json
cookie: .Dentist.Lang=c%3Dtr%7Cuic%3Dtr; dotvvm_sid_crm.megagen.com.tr=CfDJ8NRUNnxO81FMkt9W1l3UPzTQseMWWhXYc9FHqyTM%2Byofr7MrS1gjJL6jO%2F0K8y4uea6AwBAvF1h4GLscjO71wPVyZu5PdILtn6iN9AA7ueHR7oSHGHMl7z48HVW0mO%2Bx78%2BF7VxYrUvOlBdzB9IGXrJuMMyDVq12DHQqe5QRVgNn
origin: https://crm.megagen.com.tr
referer: https://crm.megagen.com.tr/Member/Login
sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
x-dotvvm-postback: true

request payload: {"currentPath":[],"command":"wpVI3fhuLTmVo63B","controlUniqueId":"","validationTargetPath":"dotvvm.viewModelObservables['root']","renderedResources":["knockout","dotvvm.polyfill.bundle","dotvvm.internal","dotvvm","dotvvm.debug"],"commandArgs":[],"knownTypeMetadata":["OrbZWyITvFhVuUA/yWHUOK5MPxQ=","5Rv8K4eLysbaJCtquQklgisMbV0=","rUxZ96wcbmlstFoHtOe8p0/1kw0=","3aRh7hTve75OuaowpI7QQrSgDIU="],"viewModel":{"$type":"OrbZWyITvFhVuUA/yWHUOK5MPxQ=","Eposta":"daltinkurt@hotmail.com","Hata":null,"Hatirla":false,"HtmlDil":"tr","Sifre":"1111","$csrfToken":"CfDJ8NRUNnxO81FMkt9W1l3UPzTAdBieRlTWbYMMb3sZwJEOi7ow2AszBZBPzkHQZte+EemQIeDLfZwqycZx1W5Ix/SJAoQgjX3mr5IBxPU+LW7OQlR37cOTcnhKfrK6EcTcN249wkzF3kBS5KRRec3N81uK8+JYv7qn+ViS+hB7u3YL"}} and this is the error message on the console:

debug DotVVM: An unhandled exception returned from the server command. dotvvm--internal:52:13
    logError https://crm.megagen.com.tr/dotvvmResource/dotvvm--internal/dotvvm--internal:52
    <anonymous> https://crm.megagen.com.tr/dotvvmResource/dotvvm--debug/dotvvm--debug:56
    trigger https://crm.megagen.com.tr/dotvvmResource/dotvvm--internal/dotvvm--internal:207
    postBack https://crm.megagen.com.tr/dotvvmResource/dotvvm--internal/dotvvm--internal:2680
    onclick Ember
daltinkurt commented 3 years ago

I added a sample page:

@viewModel DentistApp.ViewModels.TestViewModel, DentistApp

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <dot:Button Text="Click me" Click="{command: ClickMe()}"></dot:Button>
    {{value: TestString}}
</body>
</html>
public class TestViewModel : DotvvmViewModelBase
{
    public string TestString { get; set; }

    public void ClickMe()
    {
        TestString = DateTime.Now.ToLongTimeString();
    }
}

and the error occurs again: image image image

tomasherceg commented 3 years ago

Wow, I've never seen this behavior. Can you look into Startup.cs? What middlewares are registered before calling app.UseDotVVM. It seems like some middleware eats the request body.

daltinkurt commented 3 years ago

Here is the startup.cs Configure method: i tried many settings but i couldn't solve the error

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Error");
    //app.UseHsts();
}

//app.UseHttpsRedirection();
app.UseStaticFiles(new StaticFileOptions()
{
   ...
});
app.UseCookiePolicy();
app.UseRouting();

var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);

// global cors policy
app.UseCors(x => x
    .AllowAnyMethod()
    .AllowAnyHeader()
    .SetIsOriginAllowed(origin => true) // allow any origin
    .SetIsOriginAllowedToAllowWildcardSubdomains()
    .AllowCredentials()); // allow credentials

app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
// app.UseResponseCompression();
// app.UseResponseCaching();

// use DotVVM
var dotvvmConfiguration = app.UseDotVVM<DotvvmStartup>(env.ContentRootPath);
dotvvmConfiguration.AssertConfigurationIsValid();

// use static files

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Api}/{action=Index}/{id?}");
});
tomasherceg commented 3 years ago

Thanks, I'll try to make a repro project to see what's wrong.

cafour commented 3 years ago

@daltinkurt Hello, I haven't been able to reproduce the exception with the configuration above. However, once I put

app.Use(async (context, next) => {
    context.Request.Body = new MemoryStream();
    await next.Invoke();
});

before the DotVVM middleware I got the exact same exception. Please make sure none of the middlewares before DotVVM are doing anything fishy with the request.

cafour commented 3 years ago

@Mylan719 IIRC you said that you encountered this issue somewhere else as well. Can you elaborate please?

quigamdev commented 3 years ago

@cafour I had a similar problem, but we have fixed it. At this moment, it seems like this issue can't be reproduced with more detail. So I close it for now. If there are more details on this feel free to reopen it.