I already created an application with the function that could view the database through that application. When on the Visual Studio 2010 (Haven't released yet), the application that I made run smoothly and no error found. But, when I released it and made a Set-up and install it on my computer and when I run the program and click the view database, it gave the error "Object reference not set to an instance of an object, but when I check back in the Visual Studio 2010, the error didn't appear and run smoothly. Just when I install the application, the error appears.
This is the error that I am getting when run the application through installed program, not through Visual Studio 2010 (Debugging):
When I click "Continue", the program run as it is and run smoothly, I just wondering why this error appears only at the installed program, not in the debugging.
Anyone know how would that happen?
Here is the details:
It's quite likely that something got optimized away by the compiler when building in release mode, which can cause surprises at runtime. Perhaps one of your object is being initialized by a side-effect that the compiler "optimized away".
One easy way to try to get to the bottom of the problem is to wrap the call to the offending method in a try/catch, and when catching the exception, pop it up along with a full stack trace in a message box. What you're interested in is the line number where the null reference exception is actually occurring. Or better yet, write it out to a log file with any additional information you would like to know about at runtime. Then, redeploy your application, reinstall it, and give it another go. Once you figure out which object is not being initialized, then you will want to analyze your code to see why that would happen only in release builds and not in debug builds. You should look to see if you're using some sort of pattern (or anti-pattern) where it could affect other places in your code.
Related
I have created a small program in C# WinForms that runs fine when I start it in Visual Studio 2017. But when I build the solution and double click the .exe, nothing happens, no screen appears, even the task manager doesn't see it. No errors. It's like it doesn't do anything! My only guess is that I built it wrong because I used Nuget to install newtonsofts JSON.NET in the solution. Do I need to do anything differently or should just building the solution work?
[solved]
today i learned the difference between the bin and obj folder, thanks to everyone for helping
Based on your comment:
it is in the obj/debug folder of the project
It sounds like you're running the wrong .exe. The obj folder is used for temporary/misc. files from the build process (see What is obj folder generated for?).
Instead, you want to run the exe within bin\Debug, if "Debug" is the configuration you're building for. You can see which configuration at the top of VS.
Like others have also mentioned, make sure that Newtonsoft.Json.dll is being copied to that output directory as well. Programs and their dependencies need to be together, generally speaking. Otherwise, your exe will not know where to find the JSON code it needs to function.
99% of the time, you should pretend the obj directory isn't even there.
If that still isn't pointing you in the right direction, run the app from a command window. Any exception should get printed to it and the window will remain open for you to examine (and this has the benefit of not needing any additional logging or exception handling code to see this error).
For example, I wrote up a bad application that get a NullReferenceException in a method called Test that is called from Main. As you can see, the stacktrace is easily visible, even though my app has crashed (credit to ColinM for bringing this up originally).
I believe that there's a problem with the startup module. Follow the steps below
Open your Solution in visual studio
Double click on properties
Select output type to Windows Application
Make sure to set the startup object as follows
I hope it helps
I think there is only one reason
There is a command line argument predefined in Visual Studio. Your application uses this argument to be executed, without it, it closes itself too quickly and you even can't see your application opened.
Right click on your project in VS -> Properties -> Debug and see if there is a value in command line arguments
exe and their supporting files should be in the bin folder. Do not copy only exe from bin folder and try to run it. It is a good idea to write some exception code to get the detail.
For future reference, yet another reason (that I have experienced) can be
System.Diagnostics.Debug.Assert();
statements. In my case, the program executed normally when started from VS but when I run it by clicking its .exe (created in the Debug Mode) then it hung/freezed. No exceptions, no printed logs. Frustrating. Then I checked the Windows Event Viewer (Our true friend). It explicitly displayed the problem and the culprit was a Debug.Assert() statement.
The lesson learned again: Check
Windows Event Viewer > Windows Logs > Application
especially when your app hangs/freezes/deadlocks or when no app logs are available.
I have a strange error, which has started suddenly and which is driving me crazy. In my C# application, I am doing some heavy mathematical calculations and for that purpose, I am using CenterSpace's NMath library. Recently, when I started my application from inside Visual Studio 2015 in order to debug it, the application started to crash because of NullReferenceExceptions in NMath.dll, whenever I call an NMath library method (and another library which we have written, as well). In order to isolate the problem, I just run the following very basic matrix multiplication code:
static void Main(string[] args)
{
var mA = new DoubleMatrix(100, 200, 1.5);
var mB = new DoubleMatrix(200, 50, 1.2);
var mC = NMathFunctions.Product(mA, mB);
Console.WriteLine(mC[5, 6]);
Console.WriteLine("Computation finished");
Console.ReadLine();
}
The code crashes in the third line, when I call the "NMathFunctions.Product" method because of a NullReferenceException, with the following exception detail:
It seems that it crashes just in the constructor of the "NMathKernel" object, since an object reference is not properly set.
The most strange thing is, when I run the exactly same program directly from its project folder by using Windows Explorer, not within Visual Studio, the program runs perfectly: The fourth line prints "360.000000001" as expected and the "Console.ReadLine()" is reached!
I am completely clueless about the reason of this NullReferenceException error. It is not a third party dll related problem it seems, since the program only crashes when started from within the Visual Studio. This error completely blocks me from debugging my program with Visual Studio, which is a painful thing, leaves me the only option of debugging it with "Console.WriteLine" calls, from outside of Visual Studio. What can be the reason of this problem? Is something messed up with my Build settings maybe? (Which I have checked and found nothing out of order by the way) Any clues or hints are so much welcome.
In VisualStudio go to Tools -> Options -> Debugging and make sure you have Enable Just My Code option checked.
Go to Debug -> Exceptions and unckeck all Thrown chechboxes. Only leave User-unhandled checkboxes checked. Or just use the Reset all button.
After diligently working hard on code today I noticed something strange: after ending my debugging session and coming back to my MVC controller I get an actual pop up alert indicating "Object reference not set to an instance of an object". I don't get one, I get a whole cascade of them and VS basically locks up the point of needing a reboot. This seem unusual since I'm not debugging anything and this error is coming up in Visual Studio 2013 itself, not in any code errors or error panels.
What I've done to try to fix this:
Refreshed my database on localhost. This did not fix it.
Rapidly hit the keyboard shortcut to rebuild the project. This works about 75% of the time.
Try to clean the project before the alert cascade show happens. This always fixed it when coupled with a VS restart. If I run the debugger to test my web application it comes back.
This does not come back with other projects.
The code function I'm dealing with is related to quizzes - I've created tested the initial quiz taking function as of a week ago, but now I'm working on a "resume quiz" function. So very similar and some shared methods in the controller.
This is pretty much a hard stop for me since my entire IDE is useless for this part of code. Has anyone run into VS itself saying "object reference not set to an instance of an object"?
Updating for those who come to see this later:
I don't know exactly what was broken, the devenv log didn't show it.
I uninstalled all my extensions and add-ons (just VS Web Essentials, Telerik Testing Studio and Ranorex Test Automation) and then
repaired my VS install.
Lastly, I updated all frameworks in the project via the "Extensions
and Updates" option under Tools in the VS Menu and my problem went away.
Had the same issue with VS2017 and fixed it with
https://stackoverflow.com/a/36056076/3772108
Then I changed the target browser from Chrome to IE. Then F5, wait, stop the whole thing and changed it back to the chrome. Maybe this helps someone too.
when i start visual studio 2010 c# .. and open my application i got this. it stopped responding and gives me that message in the picture once my application is opened but other application works fine.
then i debug visual studio 2010 .. and i got the exception
Unhandled exception at 0x76a0b9bc in devenv.exe: 0xE0434352: 0xe0434352.
EDIT: i tried to open the .exe file in project folder in debug folder and i got this.
how to fix that ? what should i do ?
thanks in advance.
Visual Studio is vulnerable to certain exceptions that are raised in design mode. Hard to categorize them, it is an immediate crash to the desktop. The exception code says as much, 0xe0434352 is a low-level managed code exception. You'd normally work around it by checking-in an earlier revision of your control and pay extra attention to code that needs to be disabled at design time by checking the DesignMode property. Your screenshot shows as much, seems like the control is actively displaying runtime info while in design mode. Risky.
If you want to debug it then you can by starting another instance of Visual Studio and use Tools + Attach to Process to attach to the first one (devenv.exe). Debug + Exceptions, tick the Thrown boxes for CLR exceptions and Win32 exceptions. Switch back to the first instance and load your project.
i've figured out what happened .. my form got 3 usercontrol that i made before.. one of those usercontrol has a customized progressBar which is a library .. for some reason that library stopped working .. so i removed it .. then added again from that usercontrol .. then the application worked.
I'm updating an old mobile device application for better flexibility. I had basically added the ability to configure the address of our SQL server in the case that we want to use our test server as opposed to our production server. I don't think this is causing the problem, but I wanted to state it. I also upgraded the project from a VS 2003 project to a VS 2005 project.
The issue I am having is that when I try to run the program in the VS emulator for Pocket PC, I get an error. It occurs after our "main menu" form loads and the user selects the next form to load. The form is initialized without issue, but when we try to run the .ShowDialog() method, it throws a System.MissingMethodException.
I don't have a lot of experience with the Compact Framework and really have no idea where to start looking for problems. I stepped the debugger through the entire initializing process for the new form and it ran without issue. But, again, when we come to the ShowDialog call, it throws the error.
Any ideas in where to start looking or known issues would be greatly appreciated.
I'm usually getting MissingMethodException for this reason:
I've got at least two files in my project, for instance an .exe file and a .dll file
I make changes to the .dll file's source code, and recompile
VS says it deploys the new .dll file to the device, but indeed it does not (it keeps the old file)
The .exe starts up fine, but when it starts accessing the .dll file the application throws a MissingMethodException, because it can't find the methods in the old dll file.
Fix: Delete the entire application directory from the device and redeploy.
I should have added this long ago. The answer ended up being that the incorrect version of .NET was installed on the Mobile Device.
A possible issue that can cause this situation is that the DLL is not being updated when deployed. It can be caused by the DLL in question being a dependency for more than one executable.
For example let's say executable A is running on the device and it is dependent on the DLL's method callA. You are trying to debug executable B which is also dependent on the DLL but on the method callB that you just added. When Visual Studio goes to deploy the DLL with callB in it, it is unable to do so because executable A is still using it. Visual Studio does not tell you that it was not successful in deploying the DLL. (Liar VS! ;)
To fix it, kill all the executables that depend on the DLL and then deploy it.
#Felix Alcala - You got an up vote from me. I would add this as a comment to your fix because it is directly related. Alas, I did not have the rep to do so. But, I want this answer to be public because I found it helpful
Start looking in the ShowDialog method itself. The error is slightly misleading - it's not ShowDialog which it can't find, but the JIT compiler is probably trying to compile ShowDialog, and throwing that exception (because ShowDialog is trying to call something it can't find). If ShowDialog is in a different assembly, then there may be something static that can't be initialized, which could similarly cause this - but start out looking in ShowDialog itself.
Because of this, one trick to finding the problem (if it isn't obvisou) is to reduce the code in ShowDialog until you find the line causing the problem. I'd start out commenting ALL the code, to confirm my hypothesis. If you no longer get the exception, try uncommenting about half of the remaining code at a time, etc.
You can get this exception when you try to use a regular WinForm class from a compact project.