Reputation: 21
Unfortunately I haven't quite found the awnser I was looking for in the search section or any other coding forums so I'll leave my question here hopping for some closure.
I've developed a very simple C# Application , one of Windows' startup projects - the maze one, which uses a simple panel with labels and simple mouse events to trigger the placement of the pointer's position back to start.
I have succesfully published my application and it works smoothly on my computer and a few others but for some weird reason it simply won't load on my friend's laptop.
We both share the same OS (Windows 7), we both have the x64 version and the framework seems to be the same, but even though the process is displayed in the task manager, it simply won't load, even after the installation is successful.
So , the program does run but it seems like it won't load and it does not throw any exceptions or errors to be analyzed.
Therefore my question is, what are the requirements for my programs to be fully compatible with other computers ?
I appreciate the attention , I've spent a lot of time working on this matter and can't seem to find the correct awnser.
I will also display my form code for further analysis:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Labirinto
{
public partial class frmLabirinto : Form
{
// Toca um som sempre que o utilizador bater numa parede
System.Media.SoundPlayer startSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Ricardo Borges\Documents\Visual Studio 2010\Projects\Labirinto\Labirinto\Resources\doh.wav");
// Toca um som sempre que o utilizador chegar ao final do labirinto
System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Ricardo Borges\Documents\Visual Studio 2010\Projects\Labirinto\Labirinto\Resources\tada.wav");
public frmLabirinto()
{
InitializeComponent();
MoveToStart();
}
private void frmLabirinto_Load(object sender, EventArgs e)
{
}
/// <summary>
/// O método permite que o ponteiro do rato volte ao ponto inicial
/// </summary>
private void MoveToStart()
{
startSoundPlayer.Play(); //Toca o som de reinicio do jogo
Point startingPoint = panel1.Location; //ponto inicial
startingPoint.Offset(10, 10); //localizacao do ponto inicial
Cursor.Position = PointToScreen(startingPoint); //coloca o cursor no local inicial
}
private void finishLabel_MouseEnter(object sender, EventArgs e)
{
finishSoundPlayer.Play(); //Toca o som de fim de jogo
// Congratula o utilizador através de uma mensagem no ecrã
MessageBox.Show("Parabéns, encontrou a saída do labirinto");
Close();
}
private void wall_MouseEnter(object sender, EventArgs e)
{
MoveToStart(); //recoloca o ponteiro no ponto inicial ao embater numa parede
}
}
}
Upvotes: 0
Views: 1441
Reputation: 9966
I have a feeling that the hard coded values used when initialising both of the SoundPlayer objects is causing an error. As an example what if there isn't a user under the name "Ricardo Borges" on the machine that is running the application?
System.Media.SoundPlayer startSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Ricardo Borges\Documents\Visual Studio 2010\Projects\Labirinto\Labirinto\Resources\doh.wav");
System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Ricardo Borges\Documents\Visual Studio 2010\Projects\Labirinto\Labirinto\Resources\tada.wav");
Based on the MSDN documentation for the SoundPlayer object 'if the path or URL is not valid, the SoundPlayer will still be constructed, but subsequent calls to a load or play method will fail'.
The first line within the MoveToStart function has the following line:
startSoundPlayer.Play();
Referring back to MSDN for the SoundPlayer.Play method it can throw one of three different exceptions depending on the cause of the error - the FileNotFoundException seems to be a likely culprit.
Can you confirm that both the specified locations and the actual files exist on the machine having problems?
Upvotes: 1
Reputation: 300797
Have you tried using the Fusion Log viewer to diagnose any assembly load errors?
Using Fusion Log Viewer to Debug Obscure Loader Errors
If that's not the problem, add logging code to your application, and check your code for any try/catch blocks that are 'swallowing' errors.
Upvotes: 0