Exceptions:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.dll
public static IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
private void GetScoreData()
{
if (settings.Contains(dataItem2.Name))
{
this.textBlock2.Text = settings[dataItem2.Name].ToString();
}
else
{
settings.Add(dataItem2.Name, "N/A");
this.textBlock2.Text = "N/A";
}
settings.Save();
}
now in the other page
i am updating its value by doing this
ScorePage.settings["MyKey"] = moves.ToString();
so everytime i restart my emulator and run my project this exception comes.
any reason why?
The isolated storage in the emulator is not persisted after you close it.
Reference: Windows Phone Emulator: (see features)
Isolated storage is available while the emulator is running. Data in isolated storage does not persist after the emulator closes. This includes files stored in a local database, as these files reside in isolated storage.
I suggest you to use site settings over application settings.
One more thing, dont worry the windows phone is persistent.(only the emulator is not!)
After restarting the emulator (or reinstallign the app), the contents on IsolatedStorage will be deleted. If you're trying to update a setting, first check that the key exists.
Showing the line where the exception occurs and the exact text of the exception will also help with identifying the issue.
Related
I have a finished application which I would like to make available to run on the iOS and Android platforms. I have tested the application as much as possible and it works without problem. But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}
When finding random apk's online through urls, I can successfully download and install them, the user is prompted to ask if they want to install comes up. But when I upload the same apk's to Google drive, and then run the download url from Google drive, the apk's doesn't work. I get a "There was a problem while parsing the package" on the device screen. I put a log to see how much data is being downloaded. And it appears that the apk's being downloaded from google drive are barely the size of what the apk's should be. Around 50k instead of 4MB. I see a lot of questions online about this, but none have talked about Google play not sending the full file. Is there something I'm missing in order to get the full apk downloaded from Google drive? here is the code,
private void downloadApk(){
// checkVersion();
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
File folder = new File(extStorageDirectory);
folder.mkdirs();
File file = new File(folder, "app-debug.apk");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
DownloadApkTask downloadApkTask = new DownloadApkTask(APKURL,file);
downloadApkTask.execute();
}
public class DownloadApkTask extends AsyncTask<String, Void, Void> {
String fileURL;
File directory;
public DownloadApkTask(String fileURL,File directory) {
this.fileURL = fileURL;
this.directory = directory;
}
#Override
protected Void doInBackground(String... params) {
Log.v("DO in Back started","Started");
try {
FileOutputStream f = new FileOutputStream(directory);
URL u = new URL(fileURL);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
Log.v("PROGREsS", String.valueOf(len1));
f.write(buffer, 0, len1);
}
f.close();
directory.setReadable(true,false);
} catch (Exception e) {
System.out.println("exception in DownloadFile: --------"+e.toString());
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void stringReturn) {
super.onPostExecute(stringReturn);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/app-debug.apk");
Log.v("STARTING INSTALLATION","-----");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
}
Based from this page, parsing error occurs on app installment.
When you try to install an application suddenly a window pop-ups saying "there is a problem parsing the package" which means the application cannot be installed due to apk parser i.e. parsing issue.
There are several reasons why this parsing error occurs & definitely one of them is responsible for your parsing error:
File may be downloaded incompletely.
Application might be not suitable for your hardware or OS version.
Due to security issue settings
Corrupted APK file.
Follow the steps shown below for fixing the android parse error on your mobile devices:
Check Manifested app apk file.
Change the Andriomanifest.xml file to its default setting & also check the name of that file. If the original name of the file is “aap.apk” & if you renamed it as "app1.apk" then also it might cause an error. If you have some knowledge of coding, look into the app code if there is some problem with coding.
Security settings.
For the security purpose, the phone has an inbuilt setting that doesn't allow installing applications from a 3rd party provider other than mobile apps provided by play store. Don’t install an app from the non-trusted website. That might really risk your mobile.
Enable USB debugging.
Go to the settings >> Scroll down then, at last, you will see option “About device” select it.
Look for option “build number.”
Tap on “Build number” for 7 times.
You will see a message “you are now a developer.”
Once you enable to go back to settings
Choose “Developer options.”
Tick mark "USB debugging."
Corrupted App file.
The parse error may cause due to corrupted file too. In this case, download a new but complete APK file, & try again to install it again. This might help you.
Disable Antivirus.
If you have installed applications like antivirus & cleaner apps, then this can also prevent some apps installation. This prevention is due to the safety purpose of the handset. They block suspicious downloads from non-trusted sites. If you really want to install that app then disable the antivirus temporarily.
Clear cache cookies of play store.
Open google play store
Select sidebar & choose option “settings.”
In general settings, you will find out to “clear local search history.”
I am building an iOS app with Xamarin and MvvmCross the required the use of Bluetooth LE. I am trying to use this plugin:
https://github.com/aritchie/bluetoothle
Here is my code:
var server = CrossBleAdapter.Current.CreateGattServer();
await server.Start(new AdvertisementData()); // throws exception
It throws an exception when trying to start the server:
{System.ArgumentException: Invalid State - Unknown at
Plugin.BluetoothLE.Server.GattServer.Start
(Plugin.BluetoothLE.Server.AdvertisementData adData) [0x0005f] in
<4281c4bd57f24525b20baae1afdf610b>:0
Apparently this plugin is easy to use so I must be missing something obvious?
That Exception indicates that the hardware is in invalid or initializing state and can be seen here: https://github.com/aritchie/bluetoothle/blob/master/Plugin.BluetoothLE.Apple.Shared/Server/GattServer.cs#L74
if (this.manager.State != CBPeripheralManagerState.PoweredOn)
throw new ArgumentException("Invalid State - " + this.manager.State);
I believe this is a bug in the code as it does not wait for the delegate to signal that the State has changed.
I found a solution. Instead of placing the code in my Core project, I placed it inside the iOS project itself, in a ViewDidAppear function, and placed a global variable in my UIViewController class:
private IGattServer server = CrossBleAdapter.Current.CreateGattServer();
I think you need to access the adapter with the appropriate thread, or at the appropriate time (after other initialization), hence why it was crashing before. I couldn't find an appropriate place to put this in my Core project, so I'm not sure if I have to put this code in each platform. Anyhow here's a solution for anyone else with this problem.
I am working on UWP application, using Prism 6.0
My application is working totally fine in both Debug and Release modes but when i am running Windows App Certification Kit on the app packages, I keep getting this Application error - "Session state service failed". I have never seen this exception when I am installing the app packages and running the app. But I get this exception every time when WACK is running the packages.
Because of this,
I am getting error in Windows App Certification Kit - Test Results.
The error are:
FAILED
Crashes and hangs
•Error Found: The crashes and hangs test detected the following errors:◦Executable C:\Program Files\WindowsApps\10486username.SongApp_1.1.0.0_x86__5q2wmk4fv784y\SongApp.exe was detected by Windows Error Reporting and experienced a crash or hang.
◦Application 10486username.SongApp_1.1.0.0_x86__5q2wmk4fv784y was detected by Windows Error Reporting and experienced a crash or hang.
•Impact if not fixed: An app that stops responding or crashes can cause data loss and is a poor user experience.
•How to fix: Investigate and debug the app to identify and fix the problem.
FAILED
Direct3D trim after suspend
•Error Found: The Direct3D Trim after Suspend test detected the following errors:◦Application App was not running at the end of the test. It likely crashed or was terminated for having become unresponsive.
•Impact if not fixed: If the app does not call Trim on its Direct3D device, the app will not release memory allocated for its earlier 3D work. This increases the risk of apps being terminated due to system memory pressure.
•How to fix: The app should call the Trim API on its IDXGIDevice3 interface anytime it is about to be suspended.
I've built a repro with the Prism sandbox app creating a new type as model, have it serialized on suspension and watch it crash through hitting Suspend and shutdown as application lifecycle event in the Debug location toolbar.
namespace HelloWorld.Models
{
public class MyModel
{
public MyModel() {}
public MyModel(string someText)
{
SomeText = someText;
}
public string SomeText { get; set; }
}
}
In the viewmodel:
[RestorableState]
public MyModel MyModel
{
get { return _myModel; }
set { SetProperty(ref _myModel, value); }
}
After some research, I managed to solve the crash by adding following lines in the runtime directives (Default.rd.xml) file:
<!-- Add your application specific runtime directives here. -->
<Namespace Name="HelloWorld.Models" Serialize="Required PublicAndInternal">
<Type Name="MyModel" Browse="Required Public" DataContractSerializer="Required Public"/>
</Namespace>
DataContractSerializer
Optional attribute. Controls policy for serialization that uses the System.Runtime.Serialization.DataContractSerializer class.
Source: MSDN
I'm dipping my toes into Windows Azure, and I'm running into something that has to be simple, but I just can't see it.
I have this small test to play with Azure queues:
public void CanPublishSillyLittleMessageOnQueue()
{
var queueClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient();
var testQueue = queueClient.GetQueueReference("testqueue1");
testQueue.CreateIfNotExist();
var message = new CloudQueueMessage("This is a test");
testQueue.AddMessage(message);
CloudQueueMessage received;
int sleepCount = 0;
while((received = testQueue.GetMessage()) == null)
{
++sleepCount;
Thread.Sleep(25);
}
testQueue.DeleteMessage(received);
Assert.Equal(message.AsString, received.AsString);
}
It sends the message just fine - I can see it in the SQL table. However, when it hits the "testQueue.DeleteMessage(received)" method, I get this:
TestCase 'AzureExploratory.PlayingWithQueues.CanPublishSillyLittleMessageOnQueue'
failed: System.ArgumentNullException : Value cannot be null.
Parameter name: str
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImplWithRetry(Func`1 impl, RetryPolicy policy)
at Microsoft.WindowsAzure.StorageClient.CloudQueue.DeleteMessage(CloudQueueMessage message)
PlayingWithQueues.cs(75,0): at AzureExploratory.PlayingWithQueues.CanPublishSillyLittleMessageOnQueue()
which appears to be a failure somewhere down inside the guts of the Azure SDK.
I'm using VS 2010, .NET 4.0, the Azure SDK V1.2, 64-bit Win 7. The developer store service is running; I can see the messages go into the queue, I just can't delete them.
Anyone ever seen anything like this?
I figured out what's going on. The code in question was running in a xUnit test harness. Turns out that the xUnit runner doesn't set up an appdomain with a config file path by default. System.UriBuilder now hits the config file, so it blows up.
The workaround was to add an empty app.config to the test project. Now it works.
ARGH!