2012-09-14 33 views
0

當我測試此代碼:「無法加載文件或程序集」System.Device,Version = 2.0.5.0 ...「我該怎麼辦?

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"; 
     } 
    } 
莫非

這是因爲控制器是WP7應用程序,但測試器是控制檯應用程序?

謝謝!

回答

0

是的。這是因爲這個,但here you have如何從控制檯(單元測試方式)嘗試。

基本上你需要更改ProjectTypeGuids節點以匹配WP7應用程序,保存該文件,然後重新加載項目。更改節點爲:

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

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

+0

嗯......那我在哪裏輸入?我有麻煩,對不起。 – user1432233

+0

@ user1432233項目文件。但按照這裏的說明:http://dotnetcatch.wordpress.com/2010/07/26/unit-testing-nunit-a-wp7-project/他們一步一步地/ –

相關問題