-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Will this work in dot net 6 in a docker container? #8
Comments
I'm trying to create an Alexa skill for my studies and i can say that it seems not to work seamlessly. I have the same setup you are talking about: .Net 6 and the skill will be deployed in a docker container. The problem is in this piece of code: private static async Task<string> GetBodyFromRequestAsync(HttpRequest httpRequest)
{
httpRequest.Body.Position = 0;
var body = await httpRequest.ReadAsStringAsync();
httpRequest.Body.Position = 0;
return body;
} Since it sets the position of the body it gives System.NotSupportedException with the following error Then, if you try to fix with
I'm working on a solution, but any suggestion will be appreciated, |
I found the solution. If you want to use the app.Use((context, _next) =>
{
context.Request.EnableBuffering();
return _next(context);
}); If you want to use the middleware with the // CHANGES: no more context.Request.EnableRewind()
context.Request.EnableBuffering();
// Verify SignatureCertChainUrl is present
context.Request.Headers.TryGetValue("SignatureCertChainUrl", out var signatureChainUrl);
if (String.IsNullOrWhiteSpace(signatureChainUrl))
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}
Uri certUrl;
try
{
certUrl = new Uri(signatureChainUrl);
}
catch
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}
// Verify SignatureCertChainUrl is Signature
context.Request.Headers.TryGetValue("Signature", out var signature);
if (String.IsNullOrWhiteSpace(signature))
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}
// CHANGES: read the body async
string body = await new StreamReader(context.Request.Body).ReadToEndAsync();
context.Request.Body.Position = 0;
if (String.IsNullOrWhiteSpace(body))
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}
var valid = await RequestVerification.Verify(signature, certUrl, body);
if (!valid)
{
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}
await _next(context); Just a final tip: If your using this netstandard2.0 project in your .Net 6 application, you can encounter some problems with Assembly info. I fixed them by adding the following lines to your .csproj <PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup> If you want, i made a fork for using this library in an application. |
this looks like it will help although i am having an issue adding the project to my solution. did you upgrade the solution to dot net 6 if so can you please check that in to your branch. I can not get your branch to work. |
You're right.. I've integrated the library with git submodules. There should be no problems using a netstandard library with .NET 6 except the one i described above. |
I've just seen what i've done. Since i've done a git clone into the directory of my Alexa Skill, Visual Studio saw that code as if it was part of my project and not a netstandard 2.0 library. As a workaround you can do the same thing. In my spare time i'll investigate if it works as a standalone library |
I've done some experiments upgrading the library in netstandard2.1 to use C#8.0 (you can find everything in the netstandard2.1 branch); i've fixed dependency problems and then i attached the two libraries (middleware and functions) as projects to my Alexa Skill Solution. Then i started debugging everything but i keep getting this error.
Since i've already got Alexa.Net in the dependencies of all project i assume that is a runtime problem of netstandard2.1 and .net6.0; maybe some runtime error since in the MS documentation is written that
|
Will this work in dot net 6 in a docker container?
Do you have any patterns/examples now that startup.cs is removed?
based on my testing it seems to be failing on string text = new StreamReader(Request.Body).ReadToEnd(); call.
I don't currently have access to the docker logs in prd so I am not exactly sure what is failing.
Thanks
The text was updated successfully, but these errors were encountered: