gpt4 book ai didi

c# - 找不到类型 'System.Web.HttpPostedFile' 的构造函数

转载 作者:行者123 更新时间:2023-11-30 19:13:57 31 4
gpt4 key购买 nike

我正在尝试创建一个 HttpPostedFile 实例

var obj2 = Activator.CreateInstance(
typeof(HttpPostedFile),
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new object[] { },
System.Globalization.CultureInfo.CurrentCulture
);

但我收到错误消息“未找到类型为‘System.Web.HttpPostedFile’的构造函数。”。

是否有另一种方法来创建 HttpPostedFile 的实例,还是我做错了什么?

最佳答案

我刚刚遇到了同样的问题,并使用 Moq 解决了它,如下所示

var postedfile = new Mock<HttpPostedFileBase>();
postedfile.Setup(f => f.ContentLength).Returns(8192);
postedfile.Setup(f => f.FileName).Returns("myfile.txt");
postedfile.Setup(f => f.InputStream).Returns(new MemoryStream(8192));
myObject.HttpPostedFile = postedfile.Object;

关于c# - 找不到类型 'System.Web.HttpPostedFile' 的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1921543/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com