Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I made an license key system in Win-forms (C# Visual Studio) I run into an error when executing the code. Want to see the source code? see it here on github:
GitHub License key system C#

Pictures of the errors:
Visual Studio
Exe Error
Exe Error details

[!] The project is inspired by an License key system with the .WPF framework (Works fine on the .WPF Framework). I try'd to convert it to .NET because my app is written in C# .NET

Line of code that gives the error:
C#
using (StreamReader reader = new StreamReader(stream))
(in QP_Helpers.cs line 38)

This code gets the license code from any source
C#
string LicenseKeys = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/X0m6avV6");
The license keys are encrypted. The License Key in this program is =
Test


Debug:

Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.


Details:

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. **** Exception Text System.Argument Null Exception: Value cannot be null. Parameter name: stream at System.I0.StreamReader.ctor(Stream stream, Encoding encoding. Boolean dete at System. IO.StreamReader..ctor(Stream stream) at QP _Helpers.QP_Helpers. IsLicensed (String key, String resourceName) in C: \User at LicenseKey.NET buy btn_register _Click (Object sender, Event Args e)


What I have tried:

I try'd to give
C#
using (StreamReader reader = new StreamReader(stream))
an diffrent value, (this value needs to be zero)
Posted
Updated 31-Mar-22 2:51am
v4
Comments
Richard Deeming 31-Mar-22 5:31am    
The error occurs because the stream variable is null.

But since you haven't shown us where you declare or initialize that variable, we can't tell you why.
Tijn Rodrigo 31-Mar-22 8:52am    
I added the Source code, link to the github repo, sorry for this.

I normally don't ask things on forums, normally i can get it fixed myself, now i was unable to do this myself.

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 yesterday's 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, it 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, the debugger 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!
 
Share this answer
 
Comments
Tijn Rodrigo 31-Mar-22 8:47am    
I added the link to my github, here you can see everything in the project
OriginalGriff 31-Mar-22 9:03am    
What has the debugger shown you so far?
Tijn Rodrigo 31-Mar-22 9:06am    
The debugger in Visual studio:

'LicenseKey.NET.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\tijnr\source\repos\LicenseKey.NET\bin\Debug\LicenseKey.NET.exe'. Symbols loaded.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.ArgumentNullException' in mscorlib.dll
An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Value cannot be null.

'LicenseKey.NET.exe' (CLR v4.0.30319: LicenseKey.NET.exe): Loaded 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Remote Debugger\x86\Runtime\Microsoft.VisualStudio.Debugger.Runtime.Desktop.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[16480] LicenseKey.NET.exe' has exited with code 4294967295 (0xffffffff).

Details:

System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Parameter name: stream
Source=mscorlib
StackTrace:
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
at System.IO.StreamReader..ctor(Stream stream)
at QP_Helpers.QP_Helpers.IsLicensed(String key, String resourceName) in C:\Users\tijnr\source\repos\LicenseKey.NET\QP_Helpers.cs:line 38
at LicenseKey.NET.buy.btn_register_Click(Object sender, EventArgs e) in C:\Users\tijnr\source\repos\LicenseKey.NET\buy.cs:line 52
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at Syst
OriginalGriff 31-Mar-22 9:57am    
You don't know how to use a debugger, do you?

Google it.
Then put a breakpoint on line 38 of QP_Helpers.cs and *run your code in the debugger*
That's not the same thing as "run your code in VS".
Tijn Rodrigo 31-Mar-22 10:15am    
I try'd to run it in the debugger and got the same results.

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