将 .shared.cs 代码从 Web 项目转移到 silverlight 项目时如何避免丢失程序集引用
几天前我开始学习silverlight。我正在关注《Pro Business Applications with Silverlight 4》一书。
今天我在构建整个解决方案时遇到了一个问题。 (持有 silverlight 和 web 项目)我使用带有 .shared.cs 扩展名的部分类向 web 项目添加了一个简单的计算字段。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BusinessApplication1.Web
{
public partial class Product
{
public decimal ProfitMargi
{
get { return ListPrice - StandardCost; }
}
}
}
但是当我构建这个解决方案时,这个部分类被复制到 silverlight 项目,我收到以下错误:
The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?)
on:
using System.Web;
我无法从文件中删除此引用,因为它是写保护的,下次我再次构建时它将被覆盖。
这里出了什么问题?
I started learning silverlight a few day ago. I'm following the Pro Business Applications with Silverlight 4 book.
Today I encountered a problem when i build the entire solution. (holding the silverlight and the web project) I added a simple calculated field to the web project using a partial class with the .shared.cs extension.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BusinessApplication1.Web
{
public partial class Product
{
public decimal ProfitMargi
{
get { return ListPrice - StandardCost; }
}
}
}
But when I build this solution, this partial class is copied to the silverlight project where i get the following error:
The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?)
on:
using System.Web;
I cannot remove this reference from the file because it's write protected and it will be overwritten the next time i build again.
What is going wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 同意这一点,但 IIRC 您不能在 Silverlight 项目内部使用某些程序集,例如 System.Web.dll,因为它们在 .NET Framework 的 Silverlight 版本中不受支持。我可能是错的,但我似乎记得在使用 Silverlight 时遇到过类似的问题,并意识到我无法使用 .NET 中我想要的一些功能。
通过 Google 浏览,很多人似乎都说您使用 System.Web.Silverlight.dll 而不是 System.Web.dll。请参阅此处了解相关信息。
I'm not 100% on this, but IIRC you cannot use some assemblies, such as System.Web.dll, inside of Silverlight projects because they are not supported in the Silverlight version of the .NET Framework. I could be wrong on this, but I seem to recall having a similar issue when working with Silverlight and realising I couldn't use some of the functionality within .NET that I would have liked.
From having a look around on Google, a lot of people seem to be saying you use System.Web.Silverlight.dll instead of System.Web.dll. See here for some information on that.