Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Speech Platform not supported #406

Closed
endeffects opened this issue Jul 30, 2024 · 5 comments
Closed

System.Speech Platform not supported #406

endeffects opened this issue Jul 30, 2024 · 5 comments

Comments

@endeffects
Copy link

I'm trying to use System.Speech 8.0 in my Visual Studio Extension. But everytime I'm starting the speech recognition I'm receiving a PlatformNotSupported exception.

I also tried to force a windows platform compilation without luck. It worked with the old VSIX integration and the same nuget versions.

Is there any way to get it working?

@BertanAygun
Copy link
Member

From what I understand System.Speech requires Windows platform support so you may have to set your TargetFramework to net8.0-windows if it is not set to it already. Please note that out-of-proc extensibility runs on .Net Core platform while old VSIX integration runs in process in Visual Studio on .Net Framework.

Thanks,

@endeffects
Copy link
Author

endeffects commented Jul 31, 2024

Yes, that's what i've tried and it did not worked. I also verified the .net Core 8 support by writting a small console application which works. The same line of code fails when running the command in visual studio.

Console App

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Speech" Version="8.0.0" />
  </ItemGroup>

</Project>

using System.Globalization;
using System.Speech.Recognition;

var recognizer = new SpeechRecognitionEngine(CultureInfo.CurrentCulture);

Console.Read();

Default VSExtensibility Template

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.10.2084" />
    <PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.10.2084" />
    <PackageReference Include="System.Speech" Version="8.0.0" />
  </ItemGroup>
</Project>
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Commands;
using Microsoft.VisualStudio.Extensibility.Shell;
using System.Globalization;
using System.Speech.Recognition;

namespace Extension1
{
    [VisualStudioContribution]
    internal class Command1 : Command
    {
        public override CommandConfiguration CommandConfiguration => new("%Extension1.Command1.DisplayName%")
        {
            Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText),
            Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu],
        };

        public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
        {
            var recognizer = new SpeechRecognitionEngine(CultureInfo.CurrentCulture); // fails at runtime 

            await this.Extensibility.Shell().ShowPromptAsync("Hello from an extension!", PromptOptions.OK, cancellationToken);
        }
    }
}

using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.Extensibility;
using System.Globalization;
using System.Speech.Recognition;

namespace Extension1
{
    [VisualStudioContribution]
    internal class ExtensionEntrypoint : Extension
    {
        public override ExtensionConfiguration ExtensionConfiguration => new()
        {
            Metadata = new(
                    id: "Extension1.78fdd90c-c7fc-4592-baa5-dc5eb685f638",
                    version: this.ExtensionAssemblyVersion,
                    publisherName: "Publisher name",
                    displayName: "Extension1",
                    description: "Extension description"),
        };

        protected override void InitializeServices(IServiceCollection serviceCollection)
        {
            base.InitializeServices(serviceCollection);

            var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); // is true
            var osNameAndVersion = RuntimeInformation.OSDescription; // returns: Microsoft Windows 10.0.22000
            
            var recognizer = new SpeechRecognitionEngine(CultureInfo.CurrentCulture); // fails at runtime
        }
    }
}

@endeffects
Copy link
Author

endeffects commented Jul 31, 2024

I think i got a workaround for my issue which is not such great. I also think there is an issue with the way the vs plugin gets compiled or hosted because it seems to ignore the targetOS at all or for it's dependencies.

What i did is to add the correct System.Speech.dll directly to my project without using the nuget package, because the nuget package contains two versions of the dll:

correct one: .nuget\packages\system.speech\8.0.0\runtimes\win\lib\net8.0\System.Speech.dll
wrong one: .nuget\packages\system.speech\8.0.0\lib\net8.0\System.Speech.dll

	<ItemGroup>
		<Reference Include="System.Speech.dll">
			<HintPath>System.Speech.dll</HintPath>
		</Reference>
	</ItemGroup>

	<ItemGroup>
		<None Update="System.Speech.dll">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
	</ItemGroup

@BertanAygun
Copy link
Member

If there is a native dependency involved, this is likely caused by #390 which we are investigating.

@endeffects
Copy link
Author

Thanks, i think than this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants