“无法加载文件或程序集'System.Device,Version = 2.0.5.0 ......”我该怎么办?

时间:2012-09-14 22:17:22

标签: c# windows-phone-7 console .net-assembly

当我测试这段代码时:

Console.WriteLine(SwearJarController.GetLocation());

我收到错误:

SwearJarController引用一个单独的项目,这里是相关的代码:

static string baseUri = "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false";

    public static string GetLocation()
    {
        GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
        var myPosition = watcher.Position;
        double latitude = -45.856633;
        double longitude = 170.500646;

        if (!myPosition.Location.IsUnknown)
        {
            latitude = myPosition.Location.Latitude;
            longitude = myPosition.Location.Longitude;
        }

        RetrieveFormatedAddress(latitude, longitude);



        return currentLocation;
    }


    public static void RetrieveFormatedAddress(double latitude, double longitude)
    {
        string strlat = Convert.ToString(latitude);
        string strlon = Convert.ToString(longitude);

        string requestUri = string.Format(baseUri, strlat, strlon);


        WebClient wc = new WebClient();
        {
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            wc.DownloadStringAsync(new Uri(requestUri));
        }

    }


    public static string currentLocation = "Unknown";

    static void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        try
        {
            var xmlElm = XElement.Parse(e.Result);
            var status = (from elm in xmlElm.Descendants()
                          where elm.Name == "status"
                          select elm).FirstOrDefault();
            if (status.Value.ToLower() == "ok")
            {
                var res = (from elm in xmlElm.Descendants()
                           where elm.Name == "formatted_address"
                           select elm).FirstOrDefault();
                currentLocation = res.Value;
            }
            else
            {
                currentLocation = "Unknown";
            }
        }
        catch
        {
            currentLocation = "Unknown";
        }
    }

这可能是因为Controller是WP7应用程序,但测试人员是控制台应用程序吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

是。这是因为但here you have如何从控制台尝试(单元测试方式)。

基本上你需要更改ProjectTypeGuids节点以匹配WP7应用程序,保存文件然后重新加载项目。将节点更改为:

<ProjectTypeGuids>
    {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>

然后您可以成功引用WP7程序集。

相关问题