使用 HttpUtility.UrlEncode() 会使程序集的命名空间“消失”?
我有 2 个 C# 项目(我们称它们为 A 和 B)。项目A被编译为类库,项目B被编译为Windows应用程序。项目B添加了对项目A的引用。正常情况下,它们运行良好,没有任何问题。
我添加了一行使用 HttpUtility.UrlEncode() 来项目 A:
字符串编码 = HttpUtility.UrlEncode(queryString);
我还添加了“使用 System.Web”和对 System.Web.dll 的引用。虽然项目 A 仍然可以成功构建,但是当我构建项目 B 时,它给出了错误,说项目 A 的命名空间不存在。删除使用 HttpUtility.UrlEncode() 的行可以解决问题,但我确实需要该方法。
请帮我!提前致谢。
编辑:我发现问题:我将项目B的“目标框架”属性设置为“.net Framework 4 client profile”,这似乎不支持System.Web。只需将其更改为“.net Framework 4”即可正常工作。
I have 2 C# projects (let's call them A and B). Project A is compiled to Class library and project B is compiled to Windows Application. Project B is added a reference to project A. Normally, they run well, without any problem.
I added a line that use HttpUtility.UrlEncode() to project A:
string encoded = HttpUtility.UrlEncode(queryString);
and I also added 'using System.Web' and a reference to System.Web.dll. While project A still be built successfully, when I build project B, it gave me errors said that the namespace of project A does not exist. Removing the line that use HttpUtility.UrlEncode() solve the problem, but I really need that method.
Please help me! Thanks in advance.
Edit: I've found the problem: I set the "target framework" property of project B as ".net framework 4 client profile", which seems not support System.Web. Just change it to ".net framework 4" and it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布收到的实际错误消息及其所有怪癖可能会更有帮助,以获得更多帮助。
It may be more helpful to post the actual error message received with all its quirks for more assistance to be given.