在silverlight项目中使用类库

时间:2014-11-20 11:47:03

标签: c# silverlight-5.0

目前我正在开发一个基于3tiers架构(DataFormation,BusnessFormation,Chalenge)的Silverlight技术的项目,包括:

  • DataFormation:是类库
  • 的项目
  • BusnessFormation:是类型库
  • 的项目
  • EChalenge:是​​silverlight实现中的表示层

我遇到的问题,我仍然无法解决它是创建一个Web服务,允许我调用库“SqliChalenge”层中的类(层次演示,在Silverlight中执行)。

附上项目架构的屏幕截图+捕获我在尝试添加引用时遇到的错误。

enter image description here

1 个答案:

答案 0 :(得分:0)

我怀疑您的问题是由于您的Silverlight项目只能引用针对Silverlight .NET Framework子集构建的类库这一事实。 (见Alex Andersons评论)

我认为将现有的标准类库项目转换为Silverlight类库项目是不可能的(意味着官方支持)。

如果您检查.csproj文件,您会发现差异:

标准C#类库项目

...
<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  <ProjectGuid>{DFDAE6D4-0A0A-42C6-915F-31973E630AC9}</ProjectGuid>
  <OutputType>Library</OutputType>
  <AppDesignerFolder>Properties</AppDesignerFolder>
  <RootNamespace>ClassLibrary1</RootNamespace>
  <AssemblyName>ClassLibrary1</AssemblyName>
  <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  <FileAlignment>512</FileAlignment>
</PropertyGroup>
...

Silverlight类库项目:

...
<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  <ProductVersion>8.0.50727</ProductVersion>
  <SchemaVersion>2.0</SchemaVersion>
  <ProjectGuid>{F5D0D210-C435-46C6-909A-1DE3BB3DEE3B}</ProjectGuid>
  <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
  <OutputType>Library</OutputType>
  <AppDesignerFolder>Properties</AppDesignerFolder>
  <RootNamespace>SilverlightClassLibrary1</RootNamespace>
  <AssemblyName>SilverlightClassLibrary1</AssemblyName>
  <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
  <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
  <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
  <SilverlightApplication>false</SilverlightApplication>
  <ValidateXaml>true</ValidateXaml>
  <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>

尝试将Silverlight类库项目添加到您的解决方案中,并从Silverlight表示层项目中引用它。

如果引用有效,只需从业务和数据层项目中复制代码。