Hack Forums
[.NET] CodeDom Error (VB) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] CodeDom Error (VB) (/showthread.php?tid=5741244)



CodeDom Error (VB) - CacheIsAFag - Oct 21, 2017

EDIT: I have fixed this issue, It was a common bug found in .net framework 2.0, I switched to 4.5.2 and it fixed the issue :)


I'm getting this error on the Dim results line:
{"Object reference not set to an instance of an object."}

Code:

Form1 Button Press (i have 2 text boxes, one for message and one for title)
Quote: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SaveFileDialog1.ShowDialog()

Dim compiler As System.CodeDom.Compiler.ICodeCompiler = New VBCodeProvider().CreateCompiler
Dim parameters As New System.CodeDom.Compiler.CompilerParameters
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
parameters.GenerateExecutable = True
parameters.OutputAssembly = SaveFileDialog1.FileName
parameters.CompilerOptions = "/target:winexe"
Dim title As String = TextBox1.Text
Dim message As String = TextBox2.Text
Dim results As System.CodeDom.Compiler.CompilerResults = compiler.CompileAssemblyFromSource(parameters, My.Resources.SourceCode.Replace("title", title).Replace("message", message)) 'line that i'm getting the error on'
End Sub


SourceCode.txt (the stub)
Quote:Imports System
Imports System.Windows.Forms
Namespace MyApp
Public Class EntryPoint
Public Shared Sub Main()
MessageBox.Show("message", "title", MessageBoxButtons.YesNoCancel)
End Sub

End Class

End Namespace