Silverlight System.XML.Linq程序集:类型';System.Xml.Linq.XDocument';在未引用的程序集中定义
我的项目中有一些奇怪的错误:Silverlight System.XML.Linq程序集:类型';System.Xml.Linq.XDocument';在未引用的程序集中定义,silverlight,linq-to-xml,Silverlight,Linq To Xml,我的项目中有一些奇怪的错误: Error 1 The type 'System.Xml.Linq.XDocument' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 但我确实添加了对“Sys
Error 1 The type 'System.Xml.Linq.XDocument' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
但我确实添加了对“System.Xml.Linq”程序集的引用。我在“使用”部分也有
代码示例:
using System;
using System.Collections.Generic;
using System.Xml.Linq;
//...........
APIConnection VK;
public override Collection MakeCollection(
CollectionRequestContext context)
{
//............
Dictionary<string, string> q = new Dictionary<string,string>();
foreach (string item in context.Query.AllKeys)
{
q.Add(item,context.Query.Get(item));
}
///Here I have 3 errors
VK= new APIConnection("", q, ErrorHandler, true);
//Error 1: The type 'System.Xml.Linq.XDocument'
//is defined in an assembly that is not referenced.
//You must add a reference to assembly 'System.Xml.Linq...
//
//Error 2: The best overloaded method match for
//'APIConnection.APIConnection(string,
// System.Collections.Generic.Dictionary<string,string>,
// ApiCallBackHandler<System.Xml.Linq.XDocument>, bool)'
//has some invalid arguments
//
//Error 3: Argument 3: cannot convert from 'method group' to
//'ApiCallBackHandler<System.Xml.Linq.XDocument>'
//............
}
void ErrorHandler(XDocument result)
{
if (result == null)
{
throw new Exception("Something wrong...");
}
}
代码是否在应用程序程序集引用的单独Silverlight库中?如果是这样,请确保您的应用程序集(主Silverlight项目)也有对System.Xml.Linq assembly的引用;程序集引用不会自动级联 更新: 我想我以前错过了问题的症结所在。听起来您想在非Silverlight程序集(web项目)中引用Silverlight程序集(类库)。这是受支持的,但仅适用于核心Silverlight程序集的子集。Linq不是.NET可以引用的核心库之一
当我以前遇到Silverlight和.NET之间的程序集引用限制时,我选择通过链接文件而不是程序集引用使用代码共享。这是将相同代码编译成两个不同程序集的地方。有人写信解释了这项技术。你能分享APIConnection类的构造函数吗?当然可以。仅仅一分钟,我就试图重现Silverlight项目、web项目和网站中的错误——所有这些都无法引发错误。您确定所有相关项目中都包含System.Xml.Linq吗?APIConnection-在库中,我在项目中使用它。我在project和Library中都有引用。两个程序集引用的System.Xml.Linq版本和正确的Silverlight版本是否相同?否!:(Library中System.Xml.Linq的版本是2.0.5.0,而WebProject中的版本是4.0.0.0!如何将System.Xml.Linq 2.0.5.0引用到WebProject??
public APIConnection(string secret, Dictionary<string,string> query, ApiCallBackHandler<XDocument> errorCalback, bool testmode=false)
{
startInfo = new StartInfo();
if (query != null)
{
string tmp;
bool isRequiredSet = true;
isRequiredSet = query.TryGetValue("api_url", out startInfo.api_url) || isRequiredSet;
isRequiredSet = query.TryGetValue("api_id", out startInfo.api_id) || isRequiredSet;
isRequiredSet = query.TryGetValue("api_settings", out startInfo.api_settings) || isRequiredSet;
if (!isRequiredSet)
throw new ArgumentNullException("Missing required values.");
}
startInfo.server_secret = secret;
dataProvider = new DataProvider(startInfo,errorCalback);
}
public DataProvider(StartInfo info, Delegate globalErrorCallback=null)
{
startInfo = info;
_globalErrorCallback = globalErrorCallback;
}