User agent string bug during POST / CreateAsync()

I have…

  • [ x] Checked the logs and have uploaded a log file and provided a link because I found something suspicious there. Please do not post the log file in the topic because very often something important is missing.

In Visual Studio when debugging I get on CreateAsync:

Exception thrown: ‘Squidex.ClientLibrary.SquidexException’ in System.Private.CoreLib.dll
Exception thrown: ‘Squidex.ClientLibrary.SquidexException’ in System.Private.CoreLib.dll

Not seeing anything else in the squidex docker container logs.

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ x] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

Squidex throws an exception during CreateAsync() for one of my schemas.

Expected behavior

Squidex should not throw an exception. :stuck_out_tongue:

Minimal reproduction of the problem

You can use this code:
var userAgent = HttpContext.Request.Headers[“User-Agent”].ToString();
newReview.UserAgent = new Dictionary<string, string>
{
{squidexCultureName, userAgent }
};
var review = await _reviewsClient.CreateAsync(newReview, true); <-- Throws the exception.

Environment

  • [ x] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: [VERSION] Never know where to look? Could you please add some sort of “click to copy squidex version number” feature in the Squidex editorial UI, somewhere in the top right profile dropdown menu?

The squidex image is probably 2-4 months old. So not the latest, but pretty recent, still. So you know.

Browser:

  • [ x] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

I have 20+ properties in my schema c# entity.

It’s only when I try to POST with a user-agent string that it bugs out on me.

This is the user-agent string I’m trying to POST to Squidex:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36

I guess it’s not liking some of the character combos in that string?

Are you sure that you have not reverse proxy in front of your instance?

Yes.
Running on my local machine. (localhost)
No proxies in between.

Ah, I got it now. Will have a look

Thank you, appreciate it.

Is this a valid test? https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/ManipulationTests.cs#L23

It is green.

Yeah, I guess - should be enough. (y)

The problem: It is green :frowning:

1 Like

Not sure if I will be able to test it tomorrow, then it’s holidays… maybe wed/thu next week.

1 Like

I am a little bit confused.

I should have tested this earlier when it was fresh in my mind.

Anyways, here’s what I have found.

I ran the exact same code as last time and I checked the exception and this time I got a: UserAgent is not a valid parameter

Or something like that. I fixed my code and I’m too lazy to reproduce it again to get the real exception message :stuck_out_tongue:

What I did was change

    public Dictionary<string, string> UserAgent { get; set; }

to

    public Dictionary<string, string> Useragent { get; set; }

and now I can successfully create my entity in Squidex using the client library.

I’ve done this same mistake numerous times but in different entities.

Is there a way so that I can name my variable in regular c#/camel casing?

Example variable names (these work and it’s what I’m forced to use in order to be able to use the Squidex Client library to communicate with the API):

    public Dictionary<string, string> Acceptlanguageall { get; set; }
    public Dictionary<string, string> Useragent { get; set; }

These do not work (came case):

    public Dictionary<string, string> AcceptLanguageAll { get; set; }
    public Dictionary<string, string> UserAgent { get; set; }

Swagger generates these variables in this casing (Acceptlanguageall, Useragent) so I assume a config change in Swagger would be required?

Please advise!

Thanks.

You can use [JsonProperty("yourname")]

Swagger will not change the names, not sure if it is possible though.

So [JsonProperty(“yourname”)] would become [JsonProperty(“UserAgent”)] ?

And I can name my property:
public Dictionary<string, string> UserAgent { get; set; }
?

“yourname” is the field name.

Field name in swagger?

Yes, which should be the same like the field name itself in squidex.