Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

C# codedom compiler compiling errors

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to develop a code compiler using C# but the problem is that I'm getting These Errors.


Source.cs





Stub.txt


 
Saloon Keeper
Posts: 13419
300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gather that you want to compile Stub.txt using the code you wrote in Source.cs.

There's a LOT of wonkiness going on in this code.

  • Why is your class not internal and sealed/static?
  • Your class name doesn't express that its responsibility is to compile code.
  • Your method name isn't a verb and doesn't express its responsibility well.
  • Don't start local variable names with an uppercase character.
  • You are replacing placeholders in the source code that don't exist.
  • You're not using the ProviderOptions variable.
  • ProviderOptions contains both an invalid key and an invalid value. I think you meant "CompilerVersion" and "v4.7".
  • You are specifying a .NET Framework compiler version, but at the same time you're mixing in .NET Core assembly names.
  • Why are you using File.AppendAllText() in combination with line breaks? Just use File.AppendAllLines(), or even better File.AppendAllLinesAsync().
  • You are performing really non-sensical LINQ queries on the compiler application's referenced assemblies. Did you mean to use Where() instead of Select()?
  • Why use LINQ expressions to get the referenced assemblies at all?
  • Why are you using string interpolation when you're not actually interpolating anything?

  • With the last three bullet points I mean that you can rewrite:
    To:

    BUT:

    Seeing as you're compiling your source code with .NET Framework (or at least, you would if you used ProviderOptions at all and specified correct keys and values), most of the namespaces you require are contained in the System.dll assembly. Referencing .NET Core assemblies from a .NET Framework application is a bad idea.

    Try this and see how far it gets you:

    I haven't tested this code. That's up to you.

    When you get back to us, please also mention what .NET version you're using to run your compiler application.
    reply
      Bookmark Topic Watch Topic
    • New Topic