Code Monkey home page Code Monkey logo

Comments (24)

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024 1

Yes ofc

Unfortunately i am done with work for the day, but i will send the stack trace and some more info tomorrow :)

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024 1

It seems that you have an Action somewhere in your QuickBtn structure which cannot get serialized by the JSON formatter. You can mark this property with [JsonIgnore], so it will not get serialized. See the documentation for details.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024 1

https://github.com/LasseBuchAspIT/GenHttpAgain
you can find the source code here

ill send the project in a moment

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024 1

thank you very much for the help 👍 was a pleasure

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Can you give me more information about the exception that occurs? A stack trace would be great.

Please note that you do not need to pass the IRequest to your method, as you can inject it directly.

I tried the following minimal sample and it works as expected:

var auth = ApiKeyAuthentication.Create()
                               .Keys("ABC-123", "BCD-234");

var injectors = Injection.Default()
                         .Add(new UserInjector<ApiKeyUser>());

var app = Layout.Create()
                .Add("quick", ServiceResource.From<QuickService>().Injectors(injectors))
                .Authentication(auth);

Host.Create()
    .Handler(app)
    .Defaults()
    .Development()
    .Console()
    .Run();

public class QuickService
{

    [ResourceMethod("GetQuickBtns")]
    public async Task<List<int>> GetQuickBtn(ApiKeyUser user)
    {
        return await GetResult();
    }

    private static Task<List<int>> GetResult()
    {
        return Task.FromResult(new List<int>() { 1, 2, 3 });
    }

}

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

Heres the full stacktrace

image
image

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

Hi again

im pretty confused as to where this action could be as my quickBtn class is very simple

image

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Hm, I updated my sample:

var auth = ApiKeyAuthentication.Create()
                               .Keys("ABC-123", "BCD-234");

var app = Layout.Create()
                .AddService<QuickService>("quick")
                .Authentication(auth);

Host.Create()
    .Handler(app)
    .Defaults()
    .Development()
    .Console()
    .Run();

public class QuickService
{

    [ResourceMethod("GetQuickBtns")]
    public async Task<List<QuickBtn>> GetQuickBtn(IRequest req)
    {
        List<QuickBtn> returnList = new();

        try
        {
            returnList = await GetResult(req.GetUser<ApiKeyUser>()!);
        }
        catch
        {
            return new();
        }

        return returnList;
    }

    private Task<List<QuickBtn>> GetResult(ApiKeyUser user)
    {
        return Task.FromResult(new List<QuickBtn>()
        {
            new QuickBtn() { Id = 1, UserId = 4711, Name = "Me", Script = "alert('Hello World');", User = user }
        });
    }


}

public partial class QuickBtn
{

    public int Id { get; set; }

    public int UserId { get; set; }

    public string? Name { get; set; }        

    public string? Script { get; set; }

    [JsonIgnore]
    public virtual ApiKeyUser? User { get; set; }

}

But still fail to reproduce this:

image

Does removing the User property from the response change anything? I see that your class is defined partial, are there any additions to this class somewhere else?

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

Not that i know of, but the class was generated by microsoft entity framework, so there might be some hidden additions that i am unaware of

maybe try reverse engineering a class with efcore to replicate?

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Or just view an instance in the debugger, this will show you all the members. But yes, I guess EF is the issue here. I think one of the options in the context menu which opens when you click on the class will show you where the other partial class is located.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

After messing around a bit more ive found that the problem persists even when using a very simple non partial Test class

image
image

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

it appears the bug dissapears when removing await from function, even if function is still declared as async

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Hm, which version of .NET do you use and how do you run this application? Plain console or something different like WPF? And also which version of GenHTTP? There were some changes to the async functionality in the latest releases.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

both .NET and Genhttp framework are running version 7.0
ill try updating to 8.0 and see if that fixes anything

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

I think updating to GenHTTP 8.1 will resolve the issue, you can stay on .NET 7 if you like.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

Updating did not fix.
This doesnt seem to be a GenHttp issue, thanks for the help regardless

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

this appears to be a GenHttp problem after all.
below are two examples, one in AspNet and one in GenHttp

the code is essentially the same, except for a small settingsReader class, being used in the AspNET example
The AspNET version runs without issue, whereas the GenHttp version crashes...

GenHttp:
image
image

AspNET:
image
image

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

Updating to 8.0 did however get me a new error:
image

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Still fail to reproduce this. Can you ZIP and attach your GenHttpAgain sample here? Do not need connection strings or anything sensitive, just the minimal code to reproduce this issue.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

this example is running on a local Test server so i can send you a copy of the DB too if needed

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

GenHttpAgain.zip will this do?

Sorry, meant the source code and Visual Studio project. You can omit any code not related to the issue or sensitive in any way.

from genhttp.

LasseBuchAspIT avatar LasseBuchAspIT commented on June 12, 2024

The file i sent previously should have contained the projcet file no?

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Yes, I managed to reproduce this issue. Currently analyzing :)

from genhttp.

Kaliumhexacyanoferrat avatar Kaliumhexacyanoferrat commented on June 12, 2024

Found and fixed the problem in version 8.1.1 and above. Problem was caused by the return types used by EF for asynchronous operations. The release should now be available via nuget.

Thank you very much for reporting the problem and for your patience when reproducing the issue!

from genhttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.