갤러리 나 카메라에서 이미지를 가져 오는 WP7을 만들고 버튼을 눌러 base64 문자열로 인코딩하여 웹 서비스로 보냅니다. VS2010에 포함 된 WP7 에뮬레이터를 사용하고 있습니다.FileStream Windows Phone 7 초기화시 System.MethodAccessException
이렇게하려면 이미지 경로에 저장된 이미지를 열 FileStream 개체를 사용하려고합니다. 내가 FileStream을 초기화 할 때 그러나, 나는 콘솔에 메시지를 얻을 : 유형의
System.XML.dll에 발생 부하첫째 예외 '를 System.MethodAccessException' 이 LiveAndesApp.dll에서 발생
'taskhost.exe' (관리) 타입 'System.ServiceModel.Web.dll'
제 번째 예외 'System.Xml.XmlException'는
많은 System.Xml.XmlException이 뒤 따른다. 이상한 것은 FileStream 생성을 System.MethodAccessException 및 E를 캐치하는 try-catch 문에 넣었고 프로그램이 입력하지도 않고 그냥 sendSighting과 함께 계속 진행한다는 것입니다.
무엇이 잘못 되었나요? 어떻게 개선 할 수 있습니까? 고마워요!
다음은 전체 코드입니다. 이것이 그림을 변환하는 방법입니다.
public void next_Click(object sender, EventArgs e)
{
//Dependera de si seguimos flujos offline y online.
if (!offline_mode)
{
NavigationService.Navigate(new Uri("/Pages/SendInformation.xaml?mode=online", UriKind.Relative));
Controller c = new Controller();
c.sendSighting();
}
else { NavigationService.Navigate(new Uri("/Pages/SendInformation.xaml?mode=offline", UriKind.Relative)); }
이것은 Controller 클래스의 코드입니다. 간결성을 위해 웹 요청과 관련된 모든 내용을 생략했습니다.
public class Controller
{
public Controller()
{ }
/// <summary>
/// Manda un avistamiento al servicio.
/// </summary>
public void sendSighting()
{
//Obtenemos el avistamiento
AddSightingFlowObject flow_object = AddSightingFlowObject.getInstance();
//Creamos el objeto json y lo incorporamos al body del request.
JObject json = new JObject();
//Si la imagen no es nula, tenemos que procesarla.
JArray arr = new JArray(new List<String>());
if (flow_object.ImageControl != null)
{
String image_base_64 = ConvertImageToBase64(flow_object.ImagePath);
arr.Add(image_base_64);
}
else
{
arr.Add("");
}
json.Add("PhotoURL", arr);
}
public String ConvertImageToBase64(String imagePath)
{
String image_base_64 = "";
FileStream fs;
Byte[] arr;
try
{
fs = new FileStream(imagePath, FileMode.Open);
arr = new Byte[fs.Length];
fs.Read(arr, 0, arr.Length);
image_base_64 = System.Convert.ToBase64String(arr);
}
catch (System.MethodAccessException e)
{
String error = "Error: " + e.Message + "Stack Trace: " + e.StackTrace;
}
return image_base_64;
}
}
감사합니다. : D
IsolatedStorageFileStream처럼 떨어지게로 대체 할 수 System.IO 네임 스페이스의 일부입니다 만드는 클래스 next_Click에 대한 호출은 PhonePage로부터 상속받은 공용 부분 클래스입니다. 아마도 이것이 http://msdn.microsoft.com/en-us/library/system.methodaccessexception.aspx에 설명 된 바와 같이 문제의 원인 일 수 있습니다. 그러나 정의에서 부분을 삭제하려고하면 "LiveAndesApp.Pages.AddSightingSummary 유형의 선언에 부분 수정자가 없습니다.이 유형의 다른 부분 선언이 있습니다"라는 메시지가 나타납니다. 이 문제를 어떻게 해결할 수 있습니까? 감사! :디 –