Click-once application crashes after Form Load - visual-studio-2010

I saw this problem in several places on the internet, without any clear solution. I do need support to know how to detect the root cause and fix this problem for ever.
A ClickOnce application published and works on almost all computers, crashes after loading the startup form without any errors.
Crashes means -
'Verifying application requirements' dialog box checks latest updates perfectly. In case there is, it downloads automatically.
Startup form opens for maximum 1 second, then closes automatically. [frequently] OR
Startup form opens, user types a letter (or clicks the mouse), then app closes automatically. [rarely]
No error message is thrown.
This phenomenon happens only on a limited number of computers, under specific user profiles. This means that on the same computer, the app launches without problem for user 'A', while for another user it crashes.
Already tried the following, without any solution -
Uninstall/reinstall the app - in most of the cases it works, but not always. Furthermore, it sometimes crashes when publishing new updates, on computers where the app was previously working.
Certificates - publishing the app with or without certificate does not make any difference.
Delete/Create user profile - did not solve the problem.
Manually delete the user profile folder from Documents And Settings/[user]/...
No Kensington mouse driver is avaliable on the computers.
Try/Catch blocks in Program.cs or in Startup form InitializeComponents()
Any idea where the problem is coming from, and how it can be detected?
Here is the code for Program.cs
namespace NCR_MaterialToolbox
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmLogin());
}
}
}
Here is the code for frmLogin
public frmLogin()
{
InitializeComponent();
}

Related

Enabling Developer Tools Access crashes Unity and Activity Monitor

I'm facing the Developer Tools problem since yesterday. I use
Unity (several different versions, e.g. 2018.4.23),
Jetbrains Rider (updated today to 2020.1.3, yesterday 2020.1.2)
macOS Catalina 10.15.5
I was refactoring some stuff and Developer Tools asked me for the access: Developer Tools Access needs to take control of another process for debugging to continue. Enter your password to allow this...
Since then, two things are happening.
If Developer Tools Access is enabled (also tried doing this through sudo /usr/sbin/DevToolsSecurity --enable command) nearly every time when I'm changing something in code, Unity stops working (loading wheel present) and I can't turn its application off. I tried using Activity Monitor, it doesn't show any activities. I can only see the loading wheel.
I even tried killing the Unity process through kill unitypid, it "kills" the process since it's not present on the processes list, but I still can see it on my desktop, being just as down as before.
Checking Unity logs, I can see it stops on:
Begin MonoManager ReloadAssembly
custom-attrs.c:1250: (null)
assembly:/Applications/Unity/Hub/Editor/2018.4.17f1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.CoreModule.dll type:UnityException member:(null) signature:<none>
Stacktrace:
Native stacktrace:
0 libmonobdwgc-2.0.dylib 0x00000001460b4976 mono_handle_native_crash + 242
If Developer Tools Access is disabled, the application asks me a few times to enable it. After pressing Cancel a few times, Unity crashes and turns off and gives me the ability to send log error to Apple with the exception:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
abort() called
Don't really know what to do. I tried updating Rider, Catalina, installing a new Unity version.
Update: I formatted the disk and installed Catalina again, it still doesn't work.
Your help would be much appreciated!
After further investigation, I've discovered the following repro:
Create a custom attribute that derives from the PropertyAttribute that calls AssetDatabase.FindAssets("somethingsomething") in it's constructor.
Create a class (in my case it derives from the MonoBehaviour class in order to be able to call the constructor because of the gameObject placed on the scene) that contains a field that has a custom attribute mentioned above.
Add FormerlySerializedAs attribute to this field (e.g. during refactoring).
Create a gameObject with your class attached.
This will result in a pop-up window with a message that I've mentioned in my question:
Developer Tools Access needs to take control of another process for debugging to continue. Enter your password to allow this...
Example:
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
public class CustomObjectPathAttribute : PropertyAttribute
{
/// <summary>
/// Default constructor.
/// </summary>
public CustomObjectPathAttribute()
{
var guids = AssetDatabase.FindAssets("Resources");
}
}
using UnityEngine.Serialization;
[System.Serializable]
public class TestClass
{
/// <summary>
/// Path to the file.
/// </summary>
[FormerlySerializedAs("pathToFile")]
[CustomObjectPath]
public string pathToFile2 = string.Empty;
}
using System.Collections.Generic;
using UnityEngine;
public class MyBehaviour : MonoBehaviour
{
private List<TestClass> testClasses;
void Start()
{
testClasses = new List<TestClass>();
}
}
Attach the MyBehaviour script to the gameObject placed on the scene. The issue will occur after project recompilation.
Using AssetDatabase.FindAssets("Resources") in the custom attribute's constructor works fine if there's no FormerlySerializedAs attribute attached to the field in the TestClass.
I've reported the bug to the Unity QA Team and they successfully reproduced the issue. Here's the link to the Unity Issue Tracker: https://issuetracker.unity3d.com/issues/crash-when-using-assetdatabase-dot-findassets-in-a-custom-propertyattribute-and-when-formerlyserializedas-attribute-is-also-used
There's nothing more I can do at this point except of
not refactoring my fields when they have custom property attributes
attached,
not using AssetDatabase.FindAssets in my property
constructor.
This is happening to me in 2019.3.x
It generally happens when I'm testing animations and making changes while in play mode.
Nothing short of a reboot will fix the issue.

How to properly copy files to Application Scripts folder from Sandboxed App?

I'm really confused about how to properly copy files and grant permission to execute e.g. an AppleScript file from a sandboxed application. I've read several articles and threads but the more I read, the more it confuses me.
The Task
My app needs to run a very simple AppleScript from an .scpt file. To do so (if I got this right), I need to copy this file into Users/thisUser/Library/Application \Scripts/.com.developerName.appName/. Before I can interact with this folder the user needs to grant access to that folder. This can be done by showing the user an NSOpenPanel where he can select the path. After confirmation the app has access to that path and I can copy the file and later run the script (App Sandbox User Selected File must be read/write). So far so good.
The Problem(s)
I find presenting a Finder window with an empty folder to select very user unfriendly, so I was wondering if there is anything else I can do. The closest what I have found regarding this problem is drag & drop the folder "into the app" - details can be found here.
I guess I'm not the only person ever who created a (sandboxed) app which needs to run specific scripts and I can't believe that the above approach is the only possible solution!? Therefore,
can I not just have a single window with an OK button and some information above that the app needs permission to write into that folder without showing an entire Finder window?
When I was looking around for solutions I also came across several settings for the app itself. Unfortunately, the docs are very limited here and I could not really find out what the specific settings actually do and how I could test them (admittedly this is because this is my first ever app for OSX and I have basically no clue what I'm doing). One of which is the Copy Files option in the Build Phase settings of the app:
This did sound promising to me since I thought that if I install the app it will automatically copy the file to the Scripts destination (probably with some sort of user prompt) and I can use it. But it does nothing. There is no copy happening at any time, even if I deselect the Copy only when installing setting. I have also tried the different destination folders which are available in the dropdown
and unfortunately also here I
could not find out what the destinations are
nor the file has been copied to any of the destination folders on build.
I know that people here don't really like to answer questions like this in much detail since it is probably more a lack of knowledge on my side but I would really appreciate it if someone could at least help me getting into the right direction and direct me to some resources which tackle my problem!
Thanks!
Well, it seems like I have found a solution which (at least for me) seems to be more or less user friendly and within Apple's sandbox guidelines.
Again, I'm very new to app development using Xcode and SwiftUI so I'm not sure if this solution is 100% "the right way of doing it". But since it took me ages to find this out, maybe someone else can use it and speed up development!
Solution
Like I have mentioned in my question above, I was trying to get rid of the (in my opinion) pretty annoying NSOpenPanel Finder prompt, where the user is supposed to select the folder. I further asked about the Copy Files setting in the app's Build Phase tab - it turned out that this was the solution! Unfortunately, I still don't have any clue about the list of destination which are presented in the dropdown but choosing Absolute Path and inserting
Users/$USER/Library/Application Scripts/$PRODUCT_BUNDLE_IDENTIFIER
did the job! The file gets copied on every build into the app's Application Scripts directory, from which I can run scripts outside the sandbox. 🙌
The next step was to create a class which executes the script using NSUserScriptTask
import Foundation
class ExecuteAppleScript {
var status = ""
private let scriptfileUrl : URL?
init() {
do {
let destinationURL = try FileManager().url(
for: FileManager.SearchPathDirectory.applicationScriptsDirectory,
in: FileManager.SearchPathDomainMask.userDomainMask,
appropriateFor:nil,
create: true)
self.scriptfileUrl = destinationURL.appendingPathComponent("CreateMailSignature.scpt")
self.status = "Linking of scriptfile successful!"
} catch {
self.status = error.localizedDescription
self.scriptfileUrl = nil
}
}
func execute() -> String {
do {
let _: Void = try NSUserScriptTask(url: self.scriptfileUrl!).execute()
self.status = "Execution of AppleScript successful!"
} catch {
self.status = error.localizedDescription
}
return self.status
}
}
Then I have created a Button View which handles the request
import SwiftUI
struct GenerateSignatureButtonView: View {
#State var status = ""
var body: some View {
VStack(alignment: .center) {
Button(action: {
self.status = ExecuteAppleScript().execute()
})
{
Text("Generate Signature")
}
Text("\(self.status)")
}
}
}
struct GenerateSignatureButtonView_Previews: PreviewProvider {
static var previews: some View {
GenerateSignatureButtonView()
}
}
When clicking the button a window pops up that the app wants access to control (in my case) the Mail app.
This user prompt repeats every time the user closes the app, reopens it and clicks the button again. I guess this can be somehow managed with Security-Scoped-Bookmarks but I'm not yet sure how. Furthermore, the error handling is not really working in this example since the popup appears after the successful message appears in the status field. This is probably another big thing to figure out... Asynchronous?
Well, hope this helps!

Using isolated storage right after application launch seems to cause stability problems

I'm trying to add support for tracking application usage to a WP7 app (e.g., how many times has the app been run, including wakeups from tombstoning). I thought I was doing this in a pretty straight-forward way, but I'm frequently getting IsolatedStorageExceptions, and I'm kind of at a loss for debugging it at the moment.
Paraphrasing from my App.xaml.cs
private void HandleAppCounter() {
int i = 0;
settings.TryGetValue<int>("usage", out i);
i++;
settings["usage"] = i;
settings.Save();
}
I call this function when the app is launching or activating. The thing is, it works just fine. But the thing is, if I make another call to isolated storage soon after then that is what blows up. And furthermore, it seems to only blow up if the next call happens pretty soon after.. although I'm having trouble understanding that as well.
The next action performed is usually a user clicking an item in a list. If it happens immediately when it's displayed, I get a crash from isolated storage. If the user waits a few seconds after the app is launched and then clicks it, there is no crash.
If the above code in HandleAppCounter() is commented out, then the user can click either immediately or later and it never crashes.
Can anyone give me some tips on how to debug this? I'm kind of running into a wall here.
I would suggest stepping away from your custom implementation for a sec and try the same behaviour with the default IsolatedStorageSettings class, if it is still a problem then you should report it to Microsoft Connect site as a bug, otherwise there is some kind of an error in your settings class.
If you're using IsolatedStorageSettings you might want to make sure, that whenever you're querying/adding a key, the key is there, if not you must create it.
If you're using IsolatedStorage filesystem then make sure you are always closing the streams when you're reading/writing. If you don't you will get absurd exceptions.

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

VSTO Outlook Add In Problem

I am running into problems with an Outlook Add In I created. Somehow Outlook doesn't shut down properly. I've seen all the postings about using ReleaseComObject and such.
==== UPDATE ====
I tried the whole thing again, creating a new empty project in a new solution and now, after some time after shutting down Outlook the following Error message is presented to me in Visual Studio. Somehow I think I must have disabled getting that exception in the previous solutions. I don't know what it means (yet) but I will go for a hunt. Maybe this will shine some light on the issue? The effect is still the same: Outlook doesn't shut down.
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x55cdd8 to COM context 0x55cf48 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
Also when I try to remove the add in when not in safe mode (e.g. it has been loaded) Oulook locks up when hitting the remove button in the safe center). Guess that's the same cause though.
===== END OF UPDATE ====
To debug what's going on I did the simplest thing imaginable:
1) Using Visual Studio 2008 I created a new Outlook 2007 Add In Project
2) I started the debugger with the new add in.
3) After some time I close down Outlook, expecting it to properly close down.
It doesn't. The code does reach the generated ThisAddIn_Shutdown method. But, Outlook doesn't shut down.
To make sure I'm not completely insane, I downloaded, compiled and tried the extensive example found at http://code.msdn.microsoft.com/ContosoAutoOBA. Using this add in has the same effect: Outlook doesn't close down.
I tried this with no other add ins available: that doesn't make a difference.
Just for the record, below you find the generated code.
I'm using Windows 7, Visual Studio 2008, Office 2007, all updates are installed.
Is there someone that can shine a light on this. You help is greatly appreciated.
Thanks,
Bart
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace OutlookAddIn3
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
It appears that the Microsoft CRM Add In is the problem. I disabled it earlier (in fact disabled all Outlook plug ins), but apparently that isn't enough. Actually removing it from my computer solved the problem.
There seems to be a update 7 roll up for the Microsoft CRM plugin, but it refuses to install on my machine. Alas, at least I can continue with my own Outlook plug in. I will keep a post it on my screen from now own as my new CRM system.
Ah the days of VSTO development!
From memory - to fix this:
Close all instances of Outlook running (Task Manager, End Process)
Start the application by using the debug button in VS.NET
From memory; it plays up a bit when there was already an instance running.
First up.
What version of the office service pack are you running. There are loads of fixes in SP2 to help shutdown.
Are you saying that if you dont have the addin installed outlook shuts down ok ?
As I wonder if you have any other installed inder trust center. ?

Resources