What is the difference between COM interaction in C # and F #?

I have a simple F # Outlook interaction code using the Microsoft.Office.Interop.Outlook assembly. However, when I deploy it to the client machine, as soon as the application tries to do something with the interaction code, it appears because it cannot find the assembly, so I get a FileNotFoundException exception that cascades the application.

However, if I run the same code in C # (even if it is called through the F # assembly), it works fine.

open Microsoft.Office.Interop.Outlook
open System.Runtime.InteropServices
Marshal.GetActiveObject "Outlook.Application" :?> Application

Unfortunately, the code works fine on my machine, so I cannot reproduce the problem locally. But I'm more interested in understanding what is different from how F # and C # refer to this assembly? I looked through the project files myself and tried the links in two forms. The first is the form you get when you add a link to your F # project through VS: -

  <Reference Include="Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <EmbedInteropTypes>True</EmbedInteropTypes>
    <HintPath>..\..\..\..\..\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll</HintPath>
  </Reference>

I also tried setting the local copy to true and making sure that the assembly on the deployed path didn’t work (and should not be necessary - when using a C # application that does the interaction, it finds it correctly).

The second form that I saw looks like this: -

<COMReference Include="Microsoft.Office.Interop.Outlook">
  <Guid>{00062FFF-0000-0000-C000-000000000046}</Guid>
  <VersionMajor>9</VersionMajor>
  <VersionMinor>6</VersionMinor>
  <Lcid>0</Lcid>
  <WrapperTool>primary</WrapperTool>
  <Isolated>False</Isolated>
  <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>

Along with several other Interop builds.

However, none of them worked - how do F # projects differ from C # here?

+4

Source: https://habr.com/ru/post/1659151/


All Articles