将 .shared.cs 代码从 Web 项目转移到 silverlight 项目时如何避免丢失程序集引用

发布于 2024-12-27 10:31:14 字数 803 浏览 2 评论 0原文

几天前我开始学习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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生池水覆流年 2025-01-03 10:31:14

我不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文