Uri (). AbsolutePath "Unexpected character". in binding ". error expression in F #

I have an operator like this in C #:

    private static string LogPath
    {
        get
        {
            string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
            return Path.GetDirectoryName(filePath) + "/cube_solver_log.txt";
        }
    }

      

When I try to write it in F #;

static member LogPath() =
    let filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"

      

I am getting an exception:

An unexpected symbol. in the binding. An expected unfinished structured construct before or before this point or other token.

Because in F # I don't know why, the system library doesn't accept. AbsolutePath

in my code.

How can I fix the problem?

+3


source to share


1 answer


You need to add parentheses around the expression new

:

static member LogPath() =
    let filePath = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"

      



actually the keyword new

is optional, so you can:

let  LogPath() =
    let filePath = Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"

      

+2


source







All Articles