Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

VB.Net CodeDom Compiler Target Framework Issues

Hello all, I've been fooling around allot in .Net recently and stumbled across a problem that I can't quite wrap my head around.

I beleive that my code is correct and compiles my program without issues but with one catch.

Code
Public Sub Compile(ByVal Output As String, ByVal Source As String)
        On Error Resume Next
        Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler()
        Dim Parameters As New CompilerParameters()
        Dim cResults As CompilerResults
        Parameters.GenerateExecutable = True
        Parameters.OutputAssembly = Output
        Parameters.CompilerOptions = ("/win32icon:" & (Chr(34) & StubIcon & Chr(34))("/target:winexe"))
        Parameters.ReferencedAssemblies.Add("System.dll")
        Dim Version = New Dictionary(Of String, String)
        Version.Add("CompilerVersion", "v2.0")
        cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
        If cResults.Errors.Count > 0 Then
            For Each CompilerError In cResults.Errors
                MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Next
        ElseIf cResults.Errors.Count = 0 Then
        End If
    End Sub

Even though I've specified the compiler version to compile to v2.0 framework, it's compiling in v4.0

Code
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern Microsoft.VisualBasic
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 10:0:0:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly test
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module test.exe
// MVID: {AF7D08A3-6D4D-4096-8865-D551ADA33023}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x08D80000

Does anyone have any ideas on how I can fix this?
On Error Resume Next....Really?🤣🤣🤣

Your Version variable has been declared and initializated, but you dindt used anywhere on compiler options. Try to use it!!!. Example (might not work, its a guide-line code)

PHP Code

<?php 
var providerOptions = new Dictionary<string, string>();
providerOptions.Add("CompilerVersion", "v2.0");
var 
compiler = new CSharpCodeProvider(providerOptions); 
(Apr 15, 2016 12:16 PM)Zilog80 Wrote:  On Error Resume Next....Really?🤣🤣🤣

Your Version variable has been declared and initializated, but you dindt used anywhere on compiler options. Try to use it!!!. Example (might not work, its a guide-line code)

PHP Code

<?php 
var providerOptions = new Dictionary<string, string>();
providerOptions.Add("CompilerVersion", "v2.0");
var 
compiler = new CSharpCodeProvider(providerOptions); 

XD I didn't code it. It's a slightly modified version of Pr3f1x's codedom compiler function


Hmm... I can kinda see how it's been declared and all and I can see that it may not even be getting used as a variable upon compilation.. Hmmmmmmmm thank you very much I'll have to take a look into how to fix that.


The version variable still means nothing, however I've just gotten my whole project to run off of 2.0 by default.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by junkyfeet900Aug 6, 2024 10:29 PM 3 391 Aug 6, 2024 10:29 PM
Last Post: junkyfeet900
[.NET] by fisica638Feb 8, 2024 08:07 AM 8 558 Feb 8, 2024 08:07 AM
Last Post: fisica638
[.NET] by QuobiAug 6, 2022 02:23 PM 0 407 Aug 6, 2022 02:23 PM
Last Post: Quobi