找不到类型或命名空间名称“DefaultHttpRequest" [英] The type or namespace name 'DefaultHttpRequest' could not be found
问题描述
我刚刚从 2.1 升级到 .net core 3.1.
I have just upgraded to .net core 3.1 from 2.1.
我更新了所有软件包,但出现以下我无法解决的错误:
I updated all the packages but i am getting the below errors which I am not able to resolve:
The type or namespace name 'DefaultHttpRequest' could not be found
The type or namespace name 'Internal' does not exist in the namespace 'Microsoft.AspNetCore.Http'
我一直在上面使用:
using Microsoft.AspNetCore.Http.**Internal**;
private static async Task<UserInfo>
Uplpoad(byte[] buffer, FormFileCollection formFileCollection,
**DefaultHttpRequest defaultHttpRequest,**
Dictionary<string, StringValues> dictionary)
{
//some code
defaultHttpRequest.Form = new FormCollection(dictionary, formFileCollection);
//some code
}
public async void Test1Up()
{
//some code
var defaultHttpContext = new DefaultHttpContext(featureCollection);
var defaultHttpRequest = new **DefaultHttpRequest**(defaultHttpContext);
//some code
}
查看**中突出显示的行中的错误
See the error in the highlighted lines in **
我可以在 3.1 的重大更改中看到对 DefaultHttpContext 的更改,但我没有找到与 DefaultHttpRequest
相关的任何内容,这给我带来了上述错误.
I can see in the breaking changes for 3.1 there are changes to DefaultHttpContext but I didn't find anything related to DefaultHttpRequest
which is giving me errors as above.
推荐答案
DefaultHttpRequest
已从 public
更改为 internal
作为 ASP 的一部分.NET Core 3.0 版本,这意味着它不再可用.在您显示的代码中,似乎没有任何理由创建或依赖 DefaultHttpRequest
.
DefaultHttpRequest
was changed from public
to internal
as part of the ASP.NET Core 3.0 release, which means it's no longer available. In the code you've shown, there doesn't appear to be any reason to create or depend on DefaultHttpRequest
.
我建议将代码更改为如下所示:
I recommend changing the code to something like this:
private static async Task<UserInfo> Upload(byte[] buffer, FormFileCollection formFileCollection,
HttpRequest httpRequest, Dictionary<string, StringValues> dictionary)
{
// ...
httpRequest.Form = new FormCollection(dictionary, formFileCollection);
// Update all other references to defaultHttpRequest
// ...
}
public async void Test1Up() // async void is generally bad, but that's a separate issue
{
// ...
var httpContext = new DefaultHttpContext(featureCollection);
var httpRequest = httpContext.Request;
// Update all other references to defaultHttpContext and defaultHttpRequest
// ...
}
不要传递DefaultHttpRequest
,而是使用抽象的HttpRequest
.在 Upload
中设置的 Form
属性是 HttpRequest
的一部分,因此应该按原样工作.也无需创建DefaultHttpRequest
的实例:DefaultHttpContext
构造函数为您完成此操作并通过其Request提供它代码> 属性.
Rather than passing around DefaultHttpRequest
, use the abstract HttpRequest
. The Form
property being set in Upload
is part of HttpRequest
, so that should work as-is. There's also no need to create an instance of DefaultHttpRequest
: the DefaultHttpContext
constructor does this for you and provides it via its Request
property.
这篇关于找不到类型或命名空间名称“DefaultHttpRequest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!