开发者

System.XML.Linq assembly: The type 'System.Xml.Linq.XDocument' is defined in an assembly that is not referenced

I have some strange error in my project:

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'.

BUT I did add a reference to "System.Xml.Linq" assembly. Also I have it in "using" section.

Code example:

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...");
        }
    }

Just in case: 1. I have similar project with exactly the same part of code and it's work! 2. Project with error is W开发者_C百科ebProject and project that's work is a Silverlight Class Library

Why I have this error?

UPD

APIConnection constructor:

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);
    }

And DataProviders constructor is:

    public DataProvider(StartInfo info, Delegate globalErrorCallback=null)
    {
        startInfo = info;
        _globalErrorCallback = globalErrorCallback;
    }


Is the code in a separate Silverlight library that the application assembly is referencing? If so, make sure your application assembly (the main Silverlight project) also has a reference to System.Xml.Linq assembly; assembly references do not automatically cascade.

Update:

I think I missed the crux of the problem before. It sounds like you're wanting to reference a Silverlight assembly (class library) in a non-Silverlight assembly (web project). This is supported, but only for a subset of the core Silverlight assemblies. System.Xml.Linq is not one of those core libraries that .NET can reference.

When I encountered the assembly referencing limitations between Silverlight and .NET before, I opted to use code sharing through linked files rather than assembly referencing. This is where you compile the same code into two different assemblies. Here's an article someone wrote explaining the technique.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜