Comments (24)
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.
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.
https://github.com/LasseBuchAspIT/GenHttpAgain
you can find the source code here
ill send the project in a moment
from genhttp.
thank you very much for the help 👍 was a pleasure
from genhttp.
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.
Heres the full stacktrace
from genhttp.
Hi again
im pretty confused as to where this action could be as my quickBtn class is very simple
from genhttp.
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:
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.
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.
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.
After messing around a bit more ive found that the problem persists even when using a very simple non partial Test class
from genhttp.
it appears the bug dissapears when removing await from function, even if function is still declared as async
from genhttp.
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.
both .NET and Genhttp framework are running version 7.0
ill try updating to 8.0 and see if that fixes anything
from genhttp.
I think updating to GenHTTP 8.1 will resolve the issue, you can stay on .NET 7 if you like.
from genhttp.
Updating did not fix.
This doesnt seem to be a GenHttp issue, thanks for the help regardless
from genhttp.
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...
from genhttp.
Updating to 8.0 did however get me a new error:
from genhttp.
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.
this example is running on a local Test server so i can send you a copy of the DB too if needed
from genhttp.
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.
The file i sent previously should have contained the projcet file no?
from genhttp.
Yes, I managed to reproduce this issue. Currently analyzing :)
from genhttp.
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)
- Switch Sonar Scanner to Java 17+
- Allow to debug test failures
- Add a framework to embrace the REPR pattern
- Can not load the svg file at browser HOT 3
- Slightly adjust responses without the need of building a response
- Add content type for JavaScript module files (.mjs)
- Fully support the `Set-Cookie` header in all places
- Allow to provide Open API specification
- Print request information to help debugging issues
- Allow simple types to be read from body
- Allow to easily deserialize responses in tests
- Add support for dependency injection
- Add default structured error mapper
- Allow to test web applications HOT 1
- Further performance improvements HOT 3
- Reduce parser allocations by testing for known strings
- Limit server side routing to sane scenarios
- Localhost (Windows) issue when using PUT HOT 4
- Parse requests on line-basis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genhttp.