ThdK
ThdK

Reputation: 10546

How to avoid missing assembly reference when project .shared.cs code from web to silverlight project

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?

Upvotes: 0

Views: 804

Answers (1)

Samuel Slade
Samuel Slade

Reputation: 8613

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.

Upvotes: 1

Related Questions