Xamarin Android debugging: No compatible code running - visual-studio

Context
I am using VS 2017.3 to develop Xamarin.Forms application. I am trying to diagnose where and why an Exception occur on my code.
I can successfully deploy run and debug my application using the SDK Android Emulator (HAX x86).
However in case an Exception occur I can not see any information about the Exception, see attached picture, settings.
Question
Is this normal in Android debugging, or missing I something?
...and my build settings:

I wanted to expand on #Uraitz's answer because it helped me figure out the problem.
First, as he explains, you will want to add an event handler in your activity, as shown in the following code:
protected override void OnCreate(Bundle savedInstanceState)
{
...
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
...
}
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
In my case I put a breakpoint inside CurrentDomainUnhandledException so I could inspect the exception.
However, even with that breakpoint in there, I ran my code and still got a confusing no-callstack error.
At this point I thought the solution wasn't working. In fact it is, but I had to click the Play (continue) button multiple times before my app would hit the breakpoint:
After clicking that button two times, I finally hit the breakpoint:
If you want to get the callstack in the debugger, you will have to dive in a few levels before it is available, but you can do so by looking at the event args parameter.
The moral of the story is - if you have added the event handler but you still aren't hitting the breakpoint (or seeing output) - keep clicking the Continue button!

Just continue, then look through the Output, it will show you the stack trace of the exception. It is a good idea to learn how to read through the log files to find information about exceptions.

You can subscribe on each platform main constructor to UnhandledException event this will give you more information about exception before break debug.
for example in Android:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
If you need each platform explanation ask for them :)

Deleting the bin and obj folders solved it in my case.

I got similar issue, after investigating, I just have to disable the Xamarin Inspector.

Ill just throw this in the mix.
I was getting a "No compatible code running" error when attempting to break on otherwise 'working' code.
After struggling with this I decided to go back to an older version of visual studio where it didn't happening.
This gave me the idea to reset my Exception settings, and then the issue went away.
Seemingly there are a number of handled exceptions that any given library might be throwing, and if you choose to break on a particular condition you may well see this.

Related

The specified child already has a parent. You must call removeView() on the child's parent first." Facing this issue

I have used MAUI preview .and VS 2022 .When the application is run and used all functionality and press system back button and cloes the app.After cloesing the app I'm try to oepn the app that time
"{Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
"
Is Occure on my mainActivity page .
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
// TEXTVIEW
base.OnCreate(savedInstanceState);
initFontScale();
Microsoft.Maui.Essentials.Platform.Init(this, savedInstanceState);
UserDialogs.Init(this);
//Microsoft.Maui.Essentials.Platform.Init(this, savedInstanceState);
}
catch (System.Exception ex)
{
}
}
How to resolve this error .
Seems like this was reported and according to the comment in there, this should be fixed for preview 11+: github.com/dotnet/maui/issues/3511 Which VS2022 have you installed?
Installing Visual Studio 2022 v17.1 Preview 2 should give you .NET MAUI Preview 11 which should resolve the issue.

JavaFX Native Bundle Splash Screen

I'm using the javafx-maven-plugin and IntelliJ IDEA on Windows 7.
I'm trying to get a splash screen to show while my JavaFX application boots up, like this:
I tried using the SplashScreen-Image manifest entry—and that works, but only if you click on the .jar—I'm deploying the application as a Native Bundle and so the user clicks an .exe (or a shortcut to an .exe) not the actual .jar.
When you click the .exe no splash screen is shown.
This SSCCE I made will help you help me.
If I'm deploying my app using the javafx-maven-plugin, (which, if I'm not mistaken, uses the JavaFX Packager Tool, which uses Inno Setup), how can I get a splash screen to show after the user clicks the .exe?
More Findings:
Looking at the installation directory, I find a .dll called runtime\bin\splashscreen.dll. Does that mean it can be done?
The native launcher does not respect that spash-screen, it is only when being invoked by the java-executable. As the native launcher is loading the JVM internally, this won't work.
I haven't found a proper way to get this working, not even with some preloaders. Maybe you can find this helpful: https://gist.github.com/FibreFoX/294012b16fa10519674b (please ignore the deltaspike-related stuff)
Copied code:
#Override
public void start(Stage primaryStage) throws Exception {
// due to the nature of preloader being ignored within native-package, show it here
SplashScreen splashScreen = new SplashScreen();
splashScreen.show(new Stage(StageStyle.TRANSPARENT));
// needed for callback
final SomeJavaFXClassWithCDI launcherThread = this;
// for splashscreen to be shown, its needed to delay everything else as parallel task/thread (it would block otherwise)
Task cdiTask = new Task<Void>() {
#Override
protected Void call() throws Exception {
// boot CDI after javaFX-splash (this will "halt" the application due to the work done by CDI-provider
bootCDI(launcherThread);
// push javaFX-work to javaFX-thread
Platform.runLater(() -> {
primaryStage.setTitle("Some Title");
// TODO prepare your stage here !
// smooth fade-out of slashscreen
splashScreen.fadeOut((ActionEvent event) -> {
primaryStage.show();
splashScreen.hide();
});
});
return null;
}
};
// run task
new Thread(cdiTask).start();
}
In short: I'm creating my splashscreen myself.
Disclaimer: I'm the maintainer of the javafx-maven-plugin

Visual Studio 2013 not thrown user-unhandled exceptions

private void Form1_Load(object sender, EventArgs e)
{
Directory.CreateDirectory(null);
MessageBox.Show("hnjkh");
}
When I run above sample code, VS2013 says A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll. Then remaining code not work.
Is this behaviour normal?
If this behaviour is normal, when a first chance exception occured, sometimes I can not find location of the problem. Debugging in this way is very hard for large projects.
How can i find exact line of the problematic code?
I don't want to toggle exceptions for every type of exception. Also when I toggle exceptions then it is thrown even user handled. I want to show only user unhandled exceptions.
Turn on the Exceptions thrown for Common Language Runtime Exceptions
Debug->Exceptions
Select the thrown check box next to "Common Language Runtime Exceptions"
The problem discussed here. When i move codes to button1_click then it works normally. Thanks to Hans Passant.

WPF Application crashes on WIndows 7 when command executable.Start() is run

I've got a tiny Portal I´m writing, and this portal is supposed to launch installers on button click. I´m developing on VS2010 on a WinXP SP3 station, and on this machine, even fter compilation and publishing, everything works as expected. However, when i run the compiled application in Windows 7, it crashes...The application work, it just crashes when i click a button for program installation.
The programming looks like this:
private void button_access_Click(object sender, RoutedEventArgs e)
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
It specifically crashes on thr button_access_Click procedure...
Any ideas as to why this could be? I`ve tried looking around here in Stackoverflow, and in other forums, but to no avail...
Any help or direction is ganz welcome!
Try this:
try
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
}
What message are you getting?
Are you sure you want to use fixed paths in your application? If so you should at least check if the file you try to start exists beforehand. Otherwise an exception will be thrown which could be the problem here.
if (File.Exists(executablePath))
{
...
}

Test App failing on Back Button... Windows Phone 7

Ok this question stems from this question:
wp7: App failing! Can not figure out where?
I thought it was corrected but it is still failing. I ripped out all of the app.xaml.cs code and it still crashing when the search button is clicked and the back button is immediately pressed.
So... I decided to see if I could replicate the issue with a new test app. Basically I have create a basic pivot application with the default Main View Model. None of my code exists...
I press the search button and then immediately press the back button and low and behold... The SAME THING HAPPENS.... It crashes the application, the emulator shows a blank screen and the debugger stops!
So... That leads me to believe that I've found a bug in the emulator (I find this very hard to believe)... OR, my Studio environment maybe is corrupted (I'm hoping it is not).
I'm not sure where to go on this one. I don't know what the error is, and it is preventing my apps from being accepted on the market place.
Does anyone have any ideas?
I made a screen capture of what I'm seeing:
Notice that the 1st 3 search/back combos work as the boxes in the search screen are allowed to display. However, the last 2 search/back combos don't work as you will see that the boxes aren't allowed to display...
http://www.youtube.com/watch?v=XVht3OtBGaI
The error report I'm getting from Microsoft:
Comments: The application reactivate after deactivation and terminates unexpectedly.
Steps to reproduce:
1) Launch the application.
2) Select a vehicle.
3) Press the device's "Start" button.
4) Select the device's "Back" button.
5) Observe the application terminates unexpectedly and does not reactive the application.
This error is reproducible 8 out of 10 times.
The other error report from a different application:
Comments: The application terminates rather than resuming when the user attempts to return from a Search.
Steps to reproduce:
1. Launch the application
2. Select the Add + button
3. Press the Search button
4. Press the Back button
5. Observe the application terminates after a few seconds.
I noticed that:
When the following happens in the debugger:
The thread '<No Name>' (0xd1b0092) has exited with code 0 (0x0).
The thread '<No Name>' (0xd6900ba) has exited with code 0 (0x0).
That the project DOES NOT FAIL as described (100% of the time). However, if I click the back button before this, then the application fails (100% of the time).
Update #1: App.xaml.cs
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
// Ensure that required application state is persisted here.
}
OK, after hours of banging my head against my desk I have found that the emulator on some machines are having the same issue I am seeing.
So... The 1st thing I did was to wrap all my functions in Try/Catch blocks... Even the smallest functions and the ones that can't error. Then I side loaded the application to see if I can get it to crash. When I felt I sufficiently tested it on my phone I re-submitted the app. In the testing notes section I asked for them to test it on a device rather than an emulator. I never heard if they did this or not, but they passed my app, so I'm guessing that they did.
Thanks to #Praetorian and #Matt Lacey and #willmel and anyone else that took a look at this problem for me. I appreciate it!
I also noticed that If you create an new wp7 application this also happend.
Create a new application. Start it.
When it has started press the Start button and immidiately click the back button. It now says Resuming.. but nothing happens.
When you try to restart the app you only get to the splashscreen.
But I found out that if you build the app using Build=Release and dont debug the app (run it on a device) this does not occur..
Can you check if this is the case for you as well.. If so them im also in trouble

Resources