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

ITelegramBotClient.SendTextMessageAsync() System.Text.Json Polymorphic Type Resolving Exception #1402

Closed
cbagpipe opened this issue Jul 16, 2024 · 2 comments

Comments

@cbagpipe
Copy link

Steps to reproduce

  • Create simple console app
  • Create instance of TelegramBotClient
  • add usage of SendTextMessageAsync method
  • add
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<PublishTrimmed>true</PublishTrimmed>

to csproj

  • publish app
  • run published app

Expected behavior

Message sent to provided id

Actual behavior

Crash with following Exception

Unhandled exception. System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
   at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
   at System.Text.Json.JsonSerializerOptions.MakeReadOnly(Boolean)
   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions, Type)
   at System.Text.Json.JsonSerializer.Serialize(Object , Type, JsonSerializerOptions )
   at Telegram.Bot.Requests.RequestBase`1.ToHttpContent()
   at Telegram.Bot.TelegramBotClient.MakeRequestAsync[TResponse](IRequest`1, CancellationToken )
   at Telegram.Bot.TelegramBotClientExtensions.SendTextMessageAsync(ITelegramBotClient , ChatId , String , Nullable`1 , ParseMode , IEnumerable`1 , LinkPreviewOptions , Boolean , Boolean , String , ReplyParameters , IReplyMarkup , String , CancellationToken )
   at monitor.TelegramNotifier.Send(String, String) in /home/cb/monitor/TelegramNotifier.cs:line 25
   at monitor.Program.Main(String[]) in /home/cb/monitor/Program.cs:line 81
   at monitor.Program.<Main>(String[])

Environment data

NuGet Package Version: 21.6.2

.NET Version: 8

IDE: VS Code on Linux

App: Simple console app, built as single-file, self-contained and trimmed

@wiz0u
Copy link
Member

wiz0u commented Jul 16, 2024

We don't support trimming yet.

@wiz0u
Copy link
Member

wiz0u commented Jul 16, 2024

Duplicate of #1322

@wiz0u wiz0u marked this as a duplicate of #1322 Jul 16, 2024
@wiz0u wiz0u closed this as completed Jul 16, 2024
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