0

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

user2618553
  • 115
  • 1
  • 2
  • 8
  • Can you show the code where you are handling the errors? – Steven Doggart Sep 26 '13 at 17:00
  • i added them to the main question – user2618553 Sep 26 '13 at 17:09
  • What is the warning for the `Sleep` line that causes the compile to fail? What I meant with my first comment is, can you show more of the code where you are utilizing CodeDom. Specifically I was interested in the area of the code where you handled the errors returned by the CodeDom compile method. – Steven Doggart Sep 26 '13 at 17:16
  • Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated. – user2618553 Sep 26 '13 at 17:18

1 Answers1

1

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;
       }
    }
svick
  • 236,525
  • 50
  • 385
  • 514
Derek
  • 7,615
  • 5
  • 33
  • 58
  • Right, that's why I was curious to see that part of the OP's code. Good answer. It's hard to say if this is the solution, but it probably is. – Steven Doggart Sep 26 '13 at 17:52