我的项目中有一些奇怪的错误:
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...");
}
}
以防万一: 1.我有类似的项目与完全相同的代码部分,它的工作! 2.有错误的项目是WebProject和项目,它的工作是Silverlight类库
为什么我有这个错误?
APIConnection构造函数:
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);
}
DataProviders构造函数是:
public DataProvider(StartInfo info, Delegate globalErrorCallback=null)
{
startInfo = info;
_globalErrorCallback = globalErrorCallback;
}
答案 0 :(得分:2)
应用程序集正在引用的单独Silverlight库中的代码是什么?如果是这样,请确保您的应用程序程序集(主Silverlight项目)也引用System.Xml.Linq程序集;程序集引用不会自动级联。
<强>更新强>
我想我之前错过了问题的关键。听起来您想要在非Silverlight程序集(Web项目)中引用Silverlight程序集(类库)。这是受支持的,但仅适用于核心Silverlight程序集的子集。 System.Xml.Linq不是.NET可以引用的核心库之一。
当我在之前遇到Silverlight和.NET之间的程序集引用限制时,我选择通过链接文件而不是程序集引用来使用代码共享。您可以在此处将相同的代码编译为两个不同的程序集。 Here's an article有人写了解释这种技术。