RTD formula not working after migrating from .NET 4.x to .NET 7

92 Views Asked by At

I have an implementation of RTDServer working fine in .NET Framework 4.x and I am trying to upgrade to .NET 7 but still have problems.

This is my basic example in .NET 7, Server.cs:

using System;
using System.Runtime.InteropServices;
using com.lightstreamer.client;
using Microsoft.Office.Interop.Excel;

namespace Examples.RtdDemo
{
    [ComVisible(true)]
    [Guid("DB1797F5-7198-4411-8563-D05F4E904956")]
    [ProgId("lightstreamer.rtdnew12")]
    public class LsRtdServer : IServer
    {
        private int pi = 0;

        int IRtdServer.ServerStart(IRTDUpdateEvent CallbackObject)
        {
            return (int)pi;
        }

        object IRtdServer.ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
        {
            pi += TopicID;

            return ""+pi;
        }

        Array IRtdServer.RefreshData(ref int TopicCount)
        {
            object[,] data = new object[1, 1];

            data[0,0] = ""+pi;

            return data;
        }

        void IRtdServer.DisconnectData(int TopicID)
        {
            // .
        }

        int IRtdServer.Heartbeat()
        {
                return 0;
        }

        void IRtdServer.ServerTerminate()
        {
            // ..
        }
    }
}

This is the interface, IServer.cs:

using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

[ComVisible(true)]
[Guid("BA9AC84B-C7FC-41CF-8B2F-1764EB773D4B")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IServer : IRtdServer
{

}

This is the project file:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <TargetFramework Condition="'$(DefaultALC)' == 'True'">net8.0</TargetFramework>

    <!-- Indicate the assembly is providing a COM server -->
    <EnableComHosting>True</EnableComHosting>

    <!-- Generate a RegFree COM manifest -->
    <EnableRegFreeCom Condition="'$(RegFree)' == 'True'">True</EnableRegFreeCom>
</PropertyGroup>

<ItemGroup>
    <!-- Used in lieu of a Primary Interop Assembly (PIA) -->
    <Compile Include="../COMContract/*.cs" />
</ItemGroup>

<ItemGroup>
    <PackageReference Include="Lightstreamer.DotNetStandard.Client" Version="6.0.0-beta.2" />
    <PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1001" />
</ItemGroup>

<ItemGroup>
    <RuntimeHostConfigurationOption Condition="'$(DefaultALC)' == 'True'" Include="System.Runtime.InteropServices.COM.LoadComponentInDefaultContext" Value="true" />
</ItemGroup>

<Target Name="ServerUsage" Condition="'$(RegFree)' != 'True'" AfterTargets="Build">
    <Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
    <Message Importance="High" Text="The server must be COM registered in order to activate.%0aThe following commands must be executed from an elevated command prompt." />
    <Message Importance="High" Text="Register:%0a    regsvr32.exe &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
    <Message Importance="High" Text="Unregister:%0a    regsvr32.exe /u &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
</Target>

<Target Name="ServerUsage_RegFree" Condition="'$(RegFree)' == 'True'" AfterTargets="Build">
    <Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
    <Message Importance="High" Text="A RegFree COM manifest has been created for the server.%0aThe manifest '@(RegFreeComManifest->'%(Filename)%(Extension)')' must be included during server deployment.%0aThe COMServer project will copy all required outputs to the COMClient output directory." />

    <ItemGroup>
        <ServerOutput Include="$(OutputPath)*.dll" />
        <ServerOutput Include="$(OutputPath)*.runtimeconfig.json" />
        <ServerOutput Include="$(OutputPath)*.deps.json" />
        <ServerOutput Include="$(OutputPath)*.manifest" />
    </ItemGroup>

    <!-- Deploy all required server outputs -->
    <Copy SourceFiles="@(ServerOutput)" DestinationFolder="../COMClient/$(OutputPath)" />
</Target>

<Target Name="Clean_RegFree" AfterTargets="Clean">
    <ItemGroup>
        <ServerOutputToDelete Include="../COMClient/$(OutputPath)COMServer.*" />
    </ItemGroup>
    <!-- Cleanup deployed server outputs -->
    <Delete Files="@(ServerOutputToDelete)" />
</Target>

Once built I have registered the comhost.dll with regsvr32.exe. The registration succeeded but from Excel any cell with a RTD formula got "N/A". Instead with a COM client application works. Any idea what is going wrong? I missing something?

0

There are 0 best solutions below