user2618553
user2618553

Reputation: 115

how to: codedom ignoring warnings in vb.net

im trying to build an application with using Code-Dom, the problem is that the compiler treats warnings as errors, i tried to specify it's parameters but with no luck

Dim Parameters As New CompilerParameters()
Parameters.WarningLevel = 0
Parameters.TreatWarningsAsErrors = False

the compiler works when there is no warnings, but i have no idea what to do?! anything could be done?

here is one of the errors, this one about

Thread.CurrentThread.Sleep(5000)

code:

Dim text123 As String = ""
        While True
            Thread.CurrentThread.Sleep(5000)
Dim s = go()
            If s <> text123 Then
                text123 = s
                functiontext("#" , s)
            End If
        End While

and the other errors about functions that don't return values

Upvotes: 0

Views: 222

Answers (1)

Derek
Derek

Reputation: 8773

Are you sure it is not working?

objCompileResults.Errors.HasErrors will return true even if there are just warnings.

Is objCompileResults.CompiledAssembly = null?

Here is some code I used to print out compile results with errors and warnings:

 CompilerResults objCompileResults = objCodeCompiler.CompileAssemblyFromFile( objCompilerParameters, files.ToArray() );

 // Check for compiler errors.
 // TODO: order by erros first (rather than warnings)
 if ( objCompileResults.Errors.HasErrors )
 {
    string errortext = "";
    string warningtext = "";
    foreach ( CompilerError mistake in objCompileResults.Errors )
    {
       if ( mistake.IsWarning == false )
       {
          string errorString = string.Format( "{0} Line: {1} Error: {2}", mistake.FileName, mistake.Line, mistake.ErrorText );
          errortext = errortext + errorString + Environment.NewLine;
       }
       else
       {
          string warningString = string.Format( "{0} Line: {1} Warning: {2}", mistake.FileName, mistake.Line, mistake.ErrorText );
          warningtext = warningtext + warningString + Environment.NewLine;
       }
    }

Upvotes: 1

Related Questions