Click here to Skip to main content
14,693,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I am currently making an application, but I have some errors going down and I have absolutely no clue how to fix them.


Output:
Exception thrown: 'System.NullReferenceException' in Kenny UI WPF.exe

Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll

The thread 0x2668 has exited with code 0 (0x0).

The thread 0x3f1c has exited with code 0 (0x0).

Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll

Exception thrown: 'System.Reflection.TargetInvocationException' in System.Xaml.dll

Exception thrown: 'System.Reflection.TargetInvocationException' in PresentationFramework.dll

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll

Exception has been thrown by the target of an invocation.



MainWindow.xaml.cs
var TMain = Globals.Theme.Main;


ThemeInterface.cs
[Serializable]
        [Obfuscation(Feature = "renaming", Exclude = true, ApplyToMembers = true)]
        public class TBase
        {
            public uint Version;
            public TLoad Load;
            public TMain Main;
            public TScriptHub ScriptHub;
        }


The error occurres on
var TMain = Globals.Theme.Main;

The code on in the second script above is the public class that contains the TMain variable.
P.S. The error only runs in debug mode, not when I actually build the application normally. Building the application normally causes the application to not open.


Let me know if you require any more information!

Looking forward to hearing from somebody soon!

What I have tried:

Tried Googling for a solution with no luck.
Posted
Updated 22-Jan-20 4:50am
Comments
F-ES Sitecore 22-Jan-20 9:47am
   
"Globals" is null or "Globals.Theme" is null. Use the debugger to find out which. Once you've found out which, step through the code to see why it is null when you think it shouldn't be. Once you've found that out, fix the issue. Unfortunately we can't do any of that for you.

1 solution

This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterdays shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, VS will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, VS will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
   
Comments
Lord Kenny 22-Jan-20 10:36am
   
You could not have explained this any better! I am trying this method now and I believe it will work in solving the problem!
OriginalGriff 22-Jan-20 10:48am
   
You're welcome!
Lord Kenny 22-Jan-20 10:59am
   
Okay! I figured out that both TMain and Globals.Theme are null. I inserted a breakpoint at the var TMain line and the variable function that contains the code for 'var Main = new TMain" inside the ThemeInterface.cs. I don't know if these null values came up because I inserted the breakpoints though.
Lord Kenny 22-Jan-20 11:09am
   
Figured out the problem! The Theme Interface is for a theme-wpf.json file to allow people to customize their application theme. The 'var TMain = Globals.Theme.Main' is referencing the 'Main' function in the ThemeInterface which is essentially creating the theme=wpf.json contents. I think the issue is that the application cannot find the file resulting in the error. I am not too sure but I am reviewing the code to see where and when the theme-wpf.json file is being created.
OriginalGriff 22-Jan-20 11:12am
   
Sounds possible!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900