1

Why I get the error when trying to do this function:

   let compile_file path use_asms output =
    use pro = new FSharpCodeProvider()
    let opt = CompilerParameters(use_asms, output)
    let res = pro.CompileAssemblyFromFile(opt, path) // <-- Error
    if res.Errors.Count = 0 
    then Some(FileInfo(res.PathToAssembly))
    else None 

Error-code: -2147467259

Error: cant find the file specified

Now I'm trying two broken implementations:

type System.CodeDom.Compiler.ICodeCompiler with 
    member this.CompileAssemblyFromFile 
            (options:CompilerParameters,fileName:string) : CompilerResults = 
        this.CompileAssemblyFromFileBatch(options, [|fileName|])

let compile_file str assemblies output =
    let pro = new System.CodeDom.Compiler.CodeCompiler()
    let opt = CompilerParameters(assemblies, output)
    let res = pro.CompileAssemblyFromFile(opt, str)
    if res.Errors.Count = 0 then 
         Some(FileInfo(res.PathToAssembly)) 
    else None

let compile_file2 path use_asms output =
    use pro = new FSharpCodeProvider()
    let opt = CompilerParameters(use_asms, output)
    let res = pro.CompileAssemblyFromFile(opt, path)
    if res.Errors.Count = 0 
    then Some(FileInfo(res.PathToAssembly))
    else None   
dthorpe
  • 35,318
  • 5
  • 75
  • 119
RomanKovalev
  • 852
  • 3
  • 10
  • 29
  • 1
    Are you sure the file specified in `path` actually exists? – svick Mar 05 '12 at 10:40
  • Yes, I'm sure. On this path file have text: module Test let sum a b = a + b – RomanKovalev Mar 05 '12 at 10:50
  • The FSharpCodeProvider is missing some functionality. I'm pretty sure some of the functions are not implemented, maybe that's that. – Ramon Snir Mar 05 '12 at 10:51
  • Is there a way to do it differently? My project needs this functionality – RomanKovalev Mar 05 '12 at 10:52
  • @RamonSnir - I just had a look and there is some code for Code for the function - `member this.CompileAssemblyFromFile (options:CompilerParameters,fileName:string) : CompilerResults = this.CompileAssemblyFromFileBatch (options, [|fileName|]);` – John Palmer Mar 05 '12 at 10:58
  • Yeah, was looking now at some old code of mine. These functions should work. It is the CodeDom code-creation which is missing. – Ramon Snir Mar 05 '12 at 11:01
  • omg, microsoft is fine :( What can I do? >"this.CompileAssemblyFromFileBatch" I'm writing: "let pro = new System.CodeDom.Compiler.CodeCompiler()" but CodeCompiler haven't constructor now... – RomanKovalev Mar 05 '12 at 11:26
  • I think your code really shouldn't throw such exception. Have you tried specifying the full path of the source code file? – svick Mar 05 '12 at 19:41
  • >Have you tried specifying the full path - yes. To the same, FSharpCodeProvider.Parse throw NotImplemented exception... – RomanKovalev Mar 06 '12 at 08:07
  • 1
    I'm not sure what is causing the error, but since F# PowerPack is open-source, you should be able to just copy the F# code dom provider files to your project and debug that to see what command is executed and then figure out why the execution of that command failed. – Tomas Petricek Mar 06 '12 at 14:50

0 Answers0