Questions tagged [csharpcodeprovider]

.NET class that provides access to the C# compiler for compiling code.

CSharpCodeProvider can be used by applications to compile C# source code from in-memory strings or from files on disk, producing in-memory compiled assemblies or DLL files on disk.

153 questions
65
votes
8 answers

How can I extract a file from an embedded resource and save it to disk?

I'm trying to compile the code below using CSharpCodeProvider. The file is successfully compiled, but when I click on the generated EXE file, I get an error (Windows is searching for a solution to this problem) and nothing happens. When I compile…
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
53
votes
5 answers

execute c# code at runtime from code file

I have a WPF C# application that contains a button. The code of the button click is written in separate text file which will be placed in the applications runtime directory. I want to execute that code placed in the text file on the click of the…
Vinod Maurya
  • 4,167
  • 11
  • 50
  • 81
25
votes
1 answer

Instruct CodeDomProvider compiler to show errors and warning messages in English language?

I'm using the System.CodeDom features to compile code at run time and I wonder if I could specify a compiler parameter or other workaround to display the compiler errors in English language instead of using the system's default language. However, in…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
21
votes
2 answers

NHibernate query runs only once, then throws InvalidCastException

I have a simple query like below: var employeeTeam = Session.Query() .Where(x => x.StartEffective <= competency.FinalDate && // competency.FinalDate is a DateTime …
DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
15
votes
4 answers

How do I programmatically create a windows form?

I have a unique c# source file named source.cs that i compile using CSharpCodeProvider from a builder to get an executable. I would put an option on the builder whether to display the About form on application startup or not. How can i create a form…
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
7
votes
6 answers

Member is inaccessible due to its protection level error

connected within this topic: How to connect string from my class to form im trying to do solutions related to their answers (specifically answer of sir Jeremy) but this error keeps on appearing 'KeyWord.KeyWord.keywords' is inaccessible due to its…
user2118160
6
votes
1 answer

Using CSharpCodeProvider with .net 4.5 beta

I recently installed the Visual Studio 11 Beta, and I'm trying to update an existing 4.0 project to use 4.5. In the program it compiles some dynamically generated code using CSharpCodeProvider. /// /// Compile and return a reference to the…
BrandonAGr
  • 5,827
  • 5
  • 47
  • 72
6
votes
1 answer

Is it possible to target the .net4 compiler from a .net3.5 app with a CSharpCodeProvider?

I'm trying to compile a .cs file using a CSharpCodeProvider from a .net 3.5 app and I want to target the .net4 compiler but I'm getting this error "Compiler executable file csc.exe cannot be found". I have .net4 installed. Below is the code that I'm…
Loman
  • 989
  • 6
  • 10
6
votes
1 answer

Which C# compiler version to compile C# 7.3 with the CSharpCodeProvider class?

I would like to use the Microsoft.CSharp.CSharpCodeProvider class to compile C# 7.3 code. The compiler version is specified in an IDictionary that is taken as input when a new CSharpCodeProvider is created; for example, { "CompilerVersion", "v4.0"…
Narf the Mouse
  • 1,541
  • 5
  • 18
  • 30
6
votes
2 answers

Compiling Portable Class Library at run-time

In the example below... instead of compiling for .Net "v4.0", what should be provided to compile a PCL library? var compiler = new CSharpCodeProvider(new Dictionary { {"CompilerVersion", "v4.0"} });
6
votes
1 answer

Weird Assembly.Load error trying to load assembly compiled with C# code provider

I'm trying to compile an assembly from my code with C# code provider. When I access the compiled assembly with compilerResult.CompiledAssembly, everything works. However, when I instead do Assembly.Load(path), I get the following…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
4
votes
1 answer

How can we add embedded resources to a file which is compiled from a source file at run-time

I'm writing a small application which works at compiling a file from a source (.cs) code file using a function: public static bool CompileExecutable(String sourceName) { //Source file that you are compliling FileInfo sourceFile = new…
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
3
votes
1 answer

CSharpCodeProvider after Obfuscator

I'm using a Scripting system that compile at runtime, it is working good, but when I use some code obfuscator to hide my codes from "bad guys" the scripting stop to work, it returns an error: Error: CS0234 The type or namespace name "Objects" does…
Kyore
  • 388
  • 2
  • 7
  • 29
3
votes
1 answer

CSharpCodeProvider "string" contains no definition for "Select". CSCC having problems with System.Linq

I'm trying to use CSharpCodeProvider to compile a piece of code. The error is: c:\...\crust.cs(551,48) : error CS1061: 'string' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'string'…
iJynx
  • 31
  • 1
3
votes
1 answer

Possible to set absolute path for references in CSharpCodeProvider?

I'm creating new .cs-files with CodeDom and later want to compile/run them with CSharpCodeProvider but having some problem with references. The code look like this: var provider = new CSharpCodeProvider(); var compilerparams = new…
MilleB
  • 1,470
  • 2
  • 19
  • 32
1
2 3
10 11