Skip to content

Program crashes when using Excel #11928

@JohnyL

Description

@JohnyL

This issue is the continuation of this issue. This time everything happens on totally another computer. I'm using Excel 2019.

Source code

F#

open Microsoft.Office.Interop

[<EntryPoint>]
let main argv =
  let app = new Excel.ApplicationClass(Visible = true)
  let book = app.Workbooks.Add();
  let sheet = book.Worksheets.[1] :?> Excel.Worksheet;
  sheet.Range["A1"].Value <- "Hello from .NET 5!";

C#

static void Main(string[] args)
{
  var app = new Excel.Application { Visible = true };
  var book = app.Workbooks.Add();
  var sheet = book.Worksheets[1] as Excel.Worksheet;
  sheet.Range["A1"].Value = "Hello from .NET 5!";
}

Assembly

C#

image

F#

image

IL Code

C#

image

F#

IL_FSharp_Excel

.csproj File (F# and C#)

<ItemGroup>
  <COMReference Include="Microsoft.Office.Interop.Excel">
    <WrapperTool>primary</WrapperTool>
    <VersionMinor>9</VersionMinor>
    <VersionMajor>1</VersionMajor>
    <Guid>00020813-0000-0000-c000-000000000046</Guid>
    <Lcid>0</Lcid>
    <Isolated>false</Isolated>
    <EmbedInteropTypes>True</EmbedInteropTypes>
  </COMReference>
</ItemGroup>

As you can see, Excel types were not embedded into F# assembly as opposed to C# one. Moreover, as you can see on the screenshot, F# uses Excel 15.0 (Excel 2013) for some reason, although it was never installed on the computer. In C# all works perfectly.

Provide any related information (optional):

  • Operating system: Windows 10 Home x64 21H1 build 19043.1151
  • .NET Runtime: .NET 6.0.100-preview.6.21355.2
  • Editing Tools: Visual Studio 2022 17.0.0 Preview 2.1
  • Excel 2019

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions