Bug 56423 - FSharp - ArrayTypeMismatchException upon Array.map
Summary: FSharp - ArrayTypeMismatchException upon Array.map
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 5.0 (2017-02)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-14 10:17 UTC by Yves Reynhout
Modified: 2017-07-06 01:50 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 56423 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Yves Reynhout 2017-05-14 10:17:35 UTC
I get the following runtime exception, executed using fsharp interactive running on top of mono,

System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
  at (wrapper stelemref) System.Object:virt_stelemref_sealed_class (intptr,object)
  at FSI_0005.Blog.generate (FSI_0005.Blog+BlogSettings settings) [0x0008d] in <9881edeb283347c3b9f6260bc48e127e>:0 
  at FSI_0005.Build+clo@72-5.Invoke (Microsoft.FSharp.Core.Unit unitVar0) [0x00042] in <9881edeb283347c3b9f6260bc48e127e>:0 
  at Fake.TargetHelper+targetFromTemplate@209-1[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) [0x00001] in <591449acccf1c534a7450383ac491459>:0 
  at Fake.TargetHelper.runSingleTarget (Fake.TargetHelper+TargetTemplate`1[a] target) [0x0004b] in <591449acccf1c534a7450383ac491459>:0 

upon executing the following code (lives in a Blog module)

let generate (settings: BlogSettings) =
    // Generate blogposts
    let allBlogPostFiles = settings.BlogPostsDir.GetFiles("*.md", SearchOption.AllDirectories)

    let blogPosts =
        allBlogPostFiles
        |> Array.map (fun file -> 
            { 
                BlogPost.BaseDirectory = settings.BlogPostsDir
                File = file
                Metadata = readBlogPostMetadata file
            }
        )

Particularly, the Array.map is causing the problem. If I change it to a Seq (IEnumerable) there's no problem. Note this code works as is on mono 4.8 and 4.2 (Ubuntu Xenial) and .NET Fx 4.6 on windows. The GetFiles method is the one from System.IO.DirectoryInfo, which returns an array of System.IO.FileInfo objects. The map transforms those into custom BlogPost objects. Could recent changes in the following area have caused this? http://www.mono-project.com/docs/about-mono/releases/5.0.0/#lazy-array-interfaces

Whether FSharp's Array.map (https://github.com/Microsoft/visualfsharp/blob/6ce962e97de24273d167b6c174344e3017a6e4c7/src/fsharp/FSharp.Core/array.fs#L266) is at fault or the above recent changes in mono is hard to determine for me.
Comment 1 Sam Williams 2017-07-06 01:50:36 UTC
I have also found this problem with the following reproduction:

//file: repoScript.fsx
#r "../packages/FAKE/tools/FakeLib.dll"
open Fake

module Actions =
type AndroidDevice = { Name: string; DeviceSerial: string; Port: string; ExcludeCategory: string; }
let run s xs =
()

open Actions
let thing = { Name = "Tablet (Portrait)"; DeviceSerial = "93df2b67"; Port = "32021"; ExcludeCategory = "AndroidTests" }

Target "Run-Droid-UI-Online-Tests" (fun _ -> run "online" [|thing|])

RunTargetOrDefault "Run-Droid-UI-Online-Tests"

run with: mono ./packages/FAKE/tools/Fake.exe repoScript.fsx "target=Run-Droid-UI-Online-Tests"