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應用程序,但測試器是控制檯應用程序?
謝謝!
嗯......那我在哪裏輸入?我有麻煩,對不起。 – user1432233
@ user1432233項目文件。但按照這裏的說明:http://dotnetcatch.wordpress.com/2010/07/26/unit-testing-nunit-a-wp7-project/他們一步一步地/ –