puppeteer-sharp icon indicating copy to clipboard operation
puppeteer-sharp copied to clipboard

Unable to run PuppeteerSharp from the dotnet publish's output

Open hamjo opened this issue 3 years ago • 1 comments

Description

When running tests from dotnet publish's output, it fails. When running the same test from the source, it succeeds.

Complete minimal example reproducing the issue

using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PuppeteerSharp;

namespace puppeteer_sharp_publish
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public async Task TestMethod1()
        {
            var browserFetcher = new BrowserFetcher();
            await browserFetcher.DownloadAsync();
            await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });
        }
    }
}

Expected behavior:

I expect the following the output from both of these to be the same.

dotnet publish --output ./app
cd ./app
dotnet test puppeteer_sharp_publish.dll
dotnet test

Actual behavior:

dotnet test suceeds, but dotnet publish fails with the following error:

   Test method puppeteer_sharp_publish.UnitTest1.TestMethod1 threw exception:
PuppeteerSharp.ProcessException: Failed to create connection ---> PuppeteerSharp.TargetClosedException: Protocol error(Target.setDiscoverTargets): Target closed. (Connection failed to process {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"1e15f420-e681-4002-abf1-e622d2db7ae1","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}}. Error creating 'PuppeteerSharp.Helpers.Json.FlexibleStringEnumConverter'..    at Newtonsoft.Json.Serialization.JsonTypeReflector.<>c__DisplayClass20_0.<GetCreator>b__0(Object[] parameters)
   at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonConverter(Object attributeProvider)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContractConverter(Type objectType)        
   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)        
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreatePrimitiveContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader 
reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader 
reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject[T]()
   at PuppeteerSharp.Connection.ProcessIncomingMessage(ConnectionResponse obj) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Connection.cs:line 239
   at PuppeteerSharp.Connection.ProcessMessage(MessageReceivedEventArgs e) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Connection.cs:line 226)
  Stack Trace:
      at PuppeteerSharp.Connection.SendAsync(String method, Object args, Boolean waitForCallback) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Connection.cs:line 139
   at PuppeteerSharp.Browser.CreateAsync(Connection connection, String[] contextIds, Boolean ignoreHTTPSErrors, ViewPortOptions defaultViewPort, LauncherBase launcher, Func`2 targetFilter) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Browser.cs:line 527
   at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Launcher.cs:line 71
--- End of inner exception stack trace ---
    at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Launcher.cs:line 80
   at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Launcher.cs:line 86
   at puppeteer_sharp_publish.UnitTest1.TestMethod1() in D:\src\puppeteer-sharp-publish\UnitTest1.cs:line 15 
   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

Versions

  • Which version of PuppeteerSharp are you using? 5.1.0

  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0. net6.0

hamjo avatar Nov 10 '21 19:11 hamjo

It seems that the publish action is removing the empty constructor of the customer Json Converters we have.

kblok avatar Nov 25 '21 15:11 kblok

Closed due to inactivity. Feel free to reopen it if needed.

kblok avatar Dec 17 '23 20:12 kblok