저는 Xamarin Forms와 Visual Studio를 사용하여 모바일 Android 앱을 만들고 있습니다.Xamarin 폼 운영 카메라에서 빈 예외가 발생했습니다
내 모바일 앱에서 사진을 찍거나 선택하려면 CrossMedia 플러그인을 사용하고 있습니다. 처음에는 초기화에 문제가 있었으며 그 문제는 내가 타겟팅 한 잘못된 Android SDK로 인해 발생한 것으로 보입니다. SDK를 업데이트하고 모든 패키지를 업데이트 한 후 '사진 선택'옵션을 사용할 수 있었지만 여전히 카메라를 사용하면 작동하지 않으며 어떤 문제인지 파악할 수 없습니다.
다음과 같은 방법이 있습니다.
private async void TakeAPhoto(object sender, EventArgs e)
{
try
{
await CrossMedia.Current.Initialize();
}
catch (Exception exception)
{
await DisplayAlert("ERROR", "Error initializing camera!", "Ok");
}
var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
{
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });
cameraStatus = results[Permission.Camera];
storageStatus = results[Permission.Storage];
}
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No camera", "No camera available", "Ok");
return;
}
if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
{
MediaFile file;
try
{
//Exception occurs in this code.
file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
//Specify Store to Album OR Directory, not both
Directory = "App_Images",
Name = "Test.jpg"
});
}
catch (Exception exception)
{
//I've got a break point here which is being hit, but the exception is (null)
throw;
}
if (file == null)
return;
//TODO: Store image to azure.
}
else
{
await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");
//On iOS you may want to send your user to the settings screen.
//CrossPermissions.Current.OpenAppSettings();
}
}
그러나 빈 예외가 발생하는 코드를 실행하면 '(null)'이라고 표시됩니다.
비주얼 스튜디오의 디버그 창은 나에게 많은 정보를 제공하지만, 내가 여기에있는 유일한 예외는 'InvocationException'이다;
InspectorDebugSession(0): HandleTargetEvent: TargetHitBreakpoint
InspectorDebugSession(0): StateChange: EntryPointBreakpointRegistered -> EntryPointBreakpointHit
InspectorDebugSession(0): AgentBridge.InjectAssembly: /mnt/shell/emulated/0/Android/data/MyFirstAppPackage.MyFirstAppPackage/files/.__override__/inspector-temp/Xamarin.Interactive.dll
InspectorDebugSession(0): AgentBridge.InjectAssembly: Mono.Debugger.Soft.InvocationException: Exception of type 'Mono.Debugger.Soft.InvocationException' was thrown.
at Mono.Debugger.Soft.InvocationsAPI.EndInvokeMethodInternalWithResultImpl(IAsyncResult asyncResult)
at Xamarin.Interactive.IdeSupport.AgentBridge.InjectAssembly(String agentAssemblyPath) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\External\inspector-ide-integration\Xamarin.Interactive.IdeSupport\AgentBridge.cs:line 55
at Xamarin.Interactive.IdeSupport.InspectorDebuggerSession.<HandleTargetEvent>b__26_0(Object <p0>) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\External\inspector-ide-integration\Xamarin.Interactive.IdeSupport\InspectorDebuggerSession.cs:line 242
InspectorDebugSession(0): StateChange: EntryPointBreakpointHit -> Error
InspectorDebugSession(0): Disposed
나는 꽤 많은 시간 동안이 것을 알아 내려고 바빴지만, 나는이 순간을 완전히 고수하고있다. 또한 내 컴퓨터에 삼성 Galaxy S4 Mini를 연결하여 원격 디버깅을 시도했지만 동일한 오류가 발생합니다. 여기서 내가 뭘 잘못하고 있니?
아마도 디버깅 인공물. 이미 모노, 에뮬레이터/장치 및 비주얼 스튜디오의 조합이 이보다 더 이상한 것을 보았습니다. 'throw' 대신에'Debug.Write (exception.ToString());')를 시도해보고 유용한 것이 출력되는지보십시오. – dlatikay
Android 에뮬레이터에서 아무런 문제없이 기능을 실행했지만 제대로 작동했습니다. 하나의 함수에서 같은 이름의 변수에 대해 알려진 문제점입니다. 2 개의 "예외"변수가 있습니다. 1을 "ex1"로 변경하면 예외가 표시됩니다. –
유리 (Yuri)가 말했듯이, 두 종류의 예외 :'System.Exception'과'Java.Lang.Exception'. 나는 당신이 사용하고있는'Exception '타입을 모르지만, 잡는 예외는 당신이 사용하고있는 Exception에 속하지 않는 것처럼 보인다. –