BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
706 stars 284 forks source link

Loading RtspClientSharp in PowerShell module fails with "The system cannot find the file specified." #73

Open pcgeek86 opened 4 years ago

pcgeek86 commented 4 years ago

Describe the bug I am trying to load the Rtsp package into a C#-based PowerShell module on MacOS Catalina. However, an error is thrown when I try to call the command in the PowerShell module.

Test-SampleCmdlet : Could not load file or assembly 'RtspClientSharp, Version=1.3.3.0, Culture=neutral, PublicKeyToken=af963665c791e92e'. The system cannot find the file specified.
At line:1 char:1
+ Test-SampleCmdlet
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Test-SampleCmdlet], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,PSRTSP.TestSampleCmdletCommand

To Reproduce Steps to reproduce the behavior:

  1. Create a new PowerShell module, using the template
  2. In the ProcessRecord() method override, add some logic to connect to an RTSP stream
  3. Run dotnet build to create your .NET DLL (PowerShell module)
  4. In PowerShell Core, run Import-Module -Name /path/to/my.dll
  5. The module imports successfully, but when running Test-SampleCmdlet -FavoriteNumber 1 I get an error

Expected behavior

The package should be loaded, without throwing errors.

Screenshots

Screen Shot 2019-12-04 at 2 19 16 AM

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Here is the full program code, for example:

using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
using RtspClientSharp;

namespace PSRTSP
{
    [Cmdlet(VerbsDiagnostic.Test,"SampleCmdlet")]
    [OutputType(typeof(FavoriteStuff))]
    public class TestSampleCmdletCommand : PSCmdlet
    {
        [Parameter(
            Mandatory = true,
            Position = 0,
            ValueFromPipeline = true,
            ValueFromPipelineByPropertyName = true)]
        public int FavoriteNumber { get; set; }

        [Parameter(
            Position = 1,
            ValueFromPipelineByPropertyName = true)]
        [ValidateSet("Cat", "Dog", "Horse")]
        public string FavoritePet { get; set; } = "Dog";

        // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
        protected override void BeginProcessing()
        {
            WriteVerbose("Begin!");
        }

        // This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
        protected override void ProcessRecord()
        {
            var uri = new Uri("rtsp://10.5.4.23");
            var connectionParameters = new ConnectionParameters(uri);
            connectionParameters.RtpTransport = RtpTransportProtocol.TCP;

            var token = new CancellationTokenSource();
            using (var client = new RtspClient(connectionParameters)) {
                var connect = client.ConnectAsync(token.Token);
                connect.GetAwaiter().GetResult();
                Console.WriteLine("Connected to RTSP stream");
            }

            WriteObject(new FavoriteStuff { 
                FavoriteNumber = FavoriteNumber,
                FavoritePet = FavoritePet
            });
        }

        // This method will be called once at the end of pipeline execution; if no input is received, this method is not called
        protected override void EndProcessing()
        {
            WriteVerbose("End!");
        }
    }

    public class FavoriteStuff
    {
        public int FavoriteNumber { get; set; }
        public string FavoritePet { get; set; }
    }
}