Null Reference Exception not related to a Null Object - c#

I am confused ( that is easy enough!). I have a small snippet of code that I have taken a screenshot of.
The NRE arises after a failed test for a file path. Nothing there is null. The SceneryAreas object is initialized just before this test. However (and my screenshot did not pick it up) it seems that in the line SceneryAreas.Clear(); that SceneryAreas is null. Is it possible that the error is being shown on the wrong line and more to the point how could the instantiated object become null at this point?
Many thanks for any suggestions - I have never seen this before.

Your source code or symbols file is not in synch with your compiled code, hence the debugger is highlighting the wrong line.
If you recompile and re-run it should break on the line in your source which is causing the problem.

It is possible that the error's shown against the wrong line. Try rebuilding your project to make sure that the source files are in sync with the code being debugged. Also, check the stack trace under View Detail... to see exactly where the exception is being thrown.

As others said, the file does not correspond with the one used to build the assembly. The easiest way to check this is trying to set a breakpoint on the file, you will see a red circle saying that the file is different from the built one.

Related

Trying to update the managed reference registry with invalid propertyPath

I have got this error while running my project: Trying to update the managed reference registry with invalid propertyPath(likely caused by a missing reference instance)'managedReferences[5133702300286058497].value', with value '2' in Unity 2021.3.9f1 Personal.
I have no clue what causes it and the error doesn't link to any of my scripts (or anything at all).
It happens only when I click on the run button and the project still works normally after unpausing it.
Does anybody know where to look to fix it (I checked the last properties I added) or what may cause it?
Thanks for your help
I still don't what really caused this error but I managed to fix it.
After discovering that propertyPath is a method of SerializedProperty, I tried to force the reserialization of my objects.
The fix was simply to remove the main script of my project containing lots of parameters I set through the inspector (I use OdinInspector) and recreate it.

Null Reference Exception.....but the value is NOT NULL

I have a line of code string managerFirstName = "test#test.com"; that is flagging as NULL. How is this NULL....its a string that is populated when its created....is there an error with my VS2013? or a setting I need to change?
It's not the highlighted line that is crashing - the IDE is highlighting the wrong line.
The stack trace you posted mentions RFS.DotNetNuke.Service.ActiveDirectorySynchronise.something. Try and look for a line of code that uses that object - probably the line of code above the highlighted line (GetManagerForOrgUnit). Examine each of the parameters for that call and see if you can find a null reference.
If the problem is code related, not build, this looks like a threading issue. Try wrapping the whole function in a lock, and looking for how contexts could be getting mangled.
I have had this issue with VS 2022. Where this happens I get null reference and errors. I have found that this was because my debug configuration was set to Release and not debug.
Try after removing Visual Studio component cache.
Close Visual Studio (ensure devenv.exe is not present in the Task Manager) Delete the directory:
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
Restart Visual Studio
This used to happen to me in VS2k13 a lot. Basically your code is not getting rebuilt. Even after a clean/rebuild, some code refuses to compile. What used to work for me was1. Clean/rebuild. 2. Make a code change in the area of code you are looking at. 3. Put a breakpoint in the calling method. 4. Debug and f11 step line by line to your code change.
Would just like to say thank you to everyone who helped me out with this Q....I found the cause...just above the
ADUser managerUser = GetManagerNameForOrgUnit(coreData.OrgAssignment_0001.OrgUnit.ID, coreData.PersonnelNo);
there is an if statement, which during testing always stops the code from hitting GetManagerNameForOrgUnit(), I have been manually stepping over this if.
I commented it out and the code works fine.
Thanks again
I faced this problem when I was manually skipping execution of few lines (apparently unrelated code section).

Hi when i try to capture the date from a text box it was not capture when i try to watch that parameter it was showing error [duplicate]

Here is the error
Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.
I am writing a simple console app and the first line of code is this:
List<MyObjectModel> list = MyObjectModel.GetNonCompletedReturns();
and the code for the function is:
public static List<MyObjectModel> GetNonCompletedReturns()
{
MyObject service = new MyObject();
List<MyObject> entities =
(from recs in service.Retrieve() where select recs).ToList();
List<MyObjectModel> models = new List<MyObjectModel>();
foreach (MyObject entity in entities)
{
models.Add(BindModel(entity));
}
return models;
}
and if I try to step through the code, as soon as I get back to the main of my app and hover over the list, I get the error message that I showed.
Can anyone help?
If your project is compiled in release (with optimizations turned on), you may see this. Have you tried the DEBUG configuration?
This error fires only when you are trying to use Watch dialog during debug.
Try to use some other technique to output the variables, like Debug.WriteLine, Console.WriteLine and so on.
None of the answers solved my problem so I'm posting the solution that helped me.
"If there is to much data in the parameters then this error can occure,
a simple solution is to make an object, not a struct because that's a dataobject.
Put this object in your parameters instead of all the different variables,
normally the problem will no longer take place."
Here's a little trick just in case you want to examine some objects and you are not able to change the parameters:
I've created a call to a new temporary function, inside the function from where I was unable to watch my object. Then, inside that new function I was able to watch my object. After the job is done, just delete the function.
While it's true that the "Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized" error appears when in release mode, most developers just ensure that their projects are configured to compile as a debug build. BUT to be sure that you have no release-DLL issues, you also must check the references to DLLs that are in your solution and make sure that you don't have a reference to a release-build DLL. If you find that this is the case, delete the DLL reference and then add a project reference rather than a DLL reference. The project reference will ensure that your solution references debug or release versions of the DLL as specified in your build configuration.
Note that the above advice applies, of course, to only those DLLs to which you have source code and which are built from a project in your solution.
I got this too, when I hit a NullReferenceException from a 3rd party control.
In this one case, I found that if I set a breakpoint before I hit the exception, I could then single step through the rest of the code without seeing the problem.
No idea why, but this worked for me - in this case at least.
For what it's worth, this error can also be caused by an infinite loop in a property getter (simplified version below). When the debugger attempts to evaluate the property (e.g. in the watch window) the UI will hang for a few seconds and the "Cannot evaluate expression..." error will appear for many of the other properties in the same class.
public int MyProperty
{
get
{
while (true) { }
return 0;
}
}
First make sure that you're running your code in DEBUG mode and with code optimization turned off. you can turn that off from the properties of your project.
If you made all of the above and the problem persists, then it's probably a problem with the stack having Debug.Break() on top of it. The solution for this is very easy, just press F10 to move to the next line and you should be able to evaluate the expression.
You can check this SO question for more information about this issue.
I was experiencing the same error message in the Visual Studio debugger when evaluating a linq expression.
Disabling the VS debugger config setting 'Enable Just My Code' resolved the issue for me:
To enable or disable Just My Code, choose the Tools > Options menu in
Visual Studio. In the Debugging > General node, choose or clear Enable
Just My Code.
https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code
I was having same issue in Visual Studio 2017. Going to Debug> Options> Debugging> General and checking "Suppress JIT optimization on module load(Managed only)" fixed my issue

Exception is thrown at Main Function instead of actual line of code

Update 2:
Now question is not about chartArea error. Its only about breaking at the point(code line) of exception. See what i get other error. Again at main
Update :
During development i want every exception to be thrown as early as it occurs. So see this image, I have tried to throw all exceptions and this works great for me. Visual studio usually tell me the exact line what causes error
But in following case I had already spent more than two hours looking at all options of exception details (with hit and trial because I don't know exactly what will tell me the error lines) but could not find anyway where exactly is the problem with my code or data.
Actual Question
I am working on c# desktop app which contains MS Charts. On executing a particular report, I get an error shown in image. Problem is how i am unable to get this error exactly at the point (line of code) of its actual occurrence. So i would fix that line.
When I debug the code before getting this error, every line goes fine and again exception occurs in Main function. But Main function is fine for all other cases
You are trying to access ChartAreaCollection using the string indexer and have passed empty string as value like below somewhere in your code (probably in the constructor).
chart1.ChartAreas[""]
I tried in a sample code and get the same error what you have got. Only difference is that it exactly breaks in the line where I access the collection using "". Search your code for [""] and you are most likely to find it.
You added a component on your form which didn't have a name assigned to it.
Compare all your ChartAreaCollection components and see if it has a name or not

ArgumentNullException was unhandled, out of the blue

I have been working on a project on and off, but I haven't touched it for 2 months, today I came back to it and I was unable to run it due to an error.
IEnumerable<MediaTitle> query = mediaTitleCollection.OfType<FilmMedia>();
The debugger stops on this line and gives the error described in title along with
Value cannot be null. Parameter name: source
Its very frustrating since the code was working 100% before and now its dominated by this error.
I have tried to clean the solution without much luck.
Enumerable.OfType will raise an exception if the collection (mediaTitleCollection, in this case) is null.
Its very frustrating since the code was working 100% before and now its dominated by this error. I have tried to clean the solution without much luck.
You should debug your application, and look for the location where mediaTitleCollection is supposed to be set. It currently is being set to null or not being initialized properly.
What is 'source' pointed in the exception message ?! Is it a field of FileMedia ?! Do you load the values from a data source like database ?

Categories

Resources