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 ?
Related
I put it back here as I am not dreaming.
Symptom: I am unable to assign null value to type decimal?. Assigning null throws exception.
decimal? value = (decimal?) null;
This time I add a picture as evidence because apparently others do not believe my issue.
Problem persists. This is the full code I am not hiding anything. I recompiled, reloaded and restarted. I also expect this to be working. But it does not.
Has anyone experienced similar?
Clean your solution and make sure that you debug your application in the DEBUG mode or have some debugging symbols from the current build. The code that you are showing is not throwing the exception, but something else from what you didn't shown is throwing this exception. For a prototype application, in up to date Visual Studio the sample code that you are showing works fine:
As you can see, the (decimal?) cast of null is not required, so you can just remove it and recompile your application.
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).
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
I'm running a .NET 2.0 program on many computers. On one I had this error occurring repeatedly until I reset the application.
//line below was throwing the exception
this.myButton.BackgroundImage = global::myNamespace.Properties.Resources.myImage;
Exception:
ExceptionType: ArgumentException
Message: Parameter is not valid.
Source: System.Drawing
StackTrace: at System.Drawing.Image.get_Flags()
at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
at System.Windows.Forms.Control.set_BackgroundImageLayout(ImageLayout value)
The resource exists and it works fine once reset. Can anyone provide any insight as to might be happening?
I suggest you use Process Monitor to examine real-time activity on the file, and which processes might be locking it. Add a Filter where the Path is the name of the image/resource file; this should quickly show if anything is monkeying around with the file behind your back.
Yes, this is a 6 year old post! Ran into the same error today, and it took me far longer to fix than it should have. I was actually disposing my image control on startup, so I obviously couldn't adjust its background image on run-time. Might as well double check for that if you're here.
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.