Skip to content

Omitted optional COM method arguments result in nonverifiable code #907

@latkin

Description

@latkin
  • VS 2015 Update 1
  • New F# 4.0 console project, .NET 4.6.1
  • Add COM reference to "Microsoft WMI Scripting V1.2 Library"

I know COM interop issues aren't so glamorous 😢

open System
open WbemScripting

let locator =
    let comTy = Type.GetTypeFromProgID("WbemScripting.SWbemLocator")
    Activator.CreateInstance(comTy) :?> SWbemLocator

let services = locator.ConnectServer()

let resultSet = services.ExecQuery("select * from Win32_Processor")

resultSet
|> Seq.cast<SWbemObject>
|> Seq.map (fun o -> o.GetObjectText_(0))
|> Seq.iter (printfn "%s")

Above complete program compiles, but fails to verify & blows up with InvalidProgramException. Issue is a rogue ldarg.0 instruction in the main@ () method, which doesn't have any arguments.

Bogus instruction is emitted around the same place that default values for omitted COM method arguments are being loaded, which made me guess this is some mishandling of optional arguments.

Sure enough, program verifies and runs fine if you fill in all optional args manually:

let services = locator.ConnectServer(".", "", "", "", "", "", 0, null)

let resultSet = services.ExecQuery("select * from Win32_Processor", "WQL", 16, null)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions