question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`System.MemberAccessException` on initial startup with .NET Core 3.0 Preview builds

See original GitHub issue

Summary

After the DiscordClient.ConnectAsync() is called it appears that some part in WebSocket throws an exception. System.MemberAccessException: Type initializer was not callable. is thrown and every single message received leaves a warning [Event] [Warning] Could not find channel last message belonged to.. Essentially all things just break apart, like not being able to GetChannel() and whatnot…

Details

Environment

  • Raspberry Pi 3B+ with Raspbian. It was a relatively fresh install (just finished updating and installed docker). Happened when I tried:
    • Docker .NET Core 3.0 preview image (mcr.microsoft.com/dotnet/core/runtime:3.0), with framework dependent deployment builds
    • Ran directly in Raspbian, self-deployed build
  • Cannot be reproduced on Windows 10 w/ .NET Core 3.0 P5

Console output

root@90baf8ca8bbf:/app# dotnet ./AyyLmao.dll
[2019-06-05 22:03:19 +00:00] [DSharpPlus] [Info] DSharpPlus, version 4.0.0-nightly-00600
[2019-06-05 22:03:20 +00:00] [REST] [Debug] Initial Request for bucket Rate limit bucket [GET::::/gateway/bot] [0/0] 01/01/0001 00:00:00 +00:00. Allowing.
[2019-06-05 22:03:21 +00:00] [REST] [Debug] Initial Request for bucket Rate limit bucket [GET::::/users/:user_id] [0/0] 01/01/0001 00:00:00 +00:00. Allowing.
[2019-06-05 22:03:22 +00:00] [REST] [Debug] Initial Request for bucket Rate limit bucket [GET::::/oauth2/applications/:application_id] [0/0] 01/01/0001 00:00:00 +00:00. Allowing.
[2019-06-05 22:03:22 +00:00] [REST] [Debug] Initial Request for bucket Rate limit bucket [GET::::/voice/regions] [0/0] 01/01/0001 00:00:00 +00:00. Allowing.
[2019-06-05 22:03:23 +00:00] [Websocket] [Debug] Received OP 10 (HELLO) - Trying to either resume or identify.
[2019-06-05 22:03:23 +00:00] [Websocket] [Debug] Starting Heartbeat.
[2019-06-05 22:03:23 +00:00] [Websocket] [Debug] Sending Heartbeat.
[2019-06-05 22:03:23 +00:00] [Websocket] [Debug] Received WebSocket Heartbeat Ack. Ping: 203ms
[2019-06-05 22:03:24 +00:00] [Websocket] [Error] Socket swallowed an exception:
System.MemberAccessException: Type initializer was not callable.
   at System.Reflection.RuntimeConstructorInfo.ThrowNoInvokeException()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at DSharpPlus.Net.Serialization.SnowflakeArrayAsDictionaryJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, 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.CreateValueInternal(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.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject[T]()
   at DSharpPlus.DiscordClient.HandleDispatchAsync(GatewayPayload payload)
   at DSharpPlus.DiscordClient.HandleSocketMessageAsync(String data)
   at DSharpPlus.DiscordClient.<InternalConnectAsync>g__SocketOnMessage|60_1(SocketMessageEventArgs e)

// A message was sent in Discord guild that the bot belongs to
[2019-06-05 22:03:39 +00:00] [Event] [Warning] Could not find channel last message belonged to.

Steps to reproduce

  1. write some nice bots using DSharpPlus :^)
  2. Enable internal logging feature
  3. Run it on Linux ARM64 build of .NET Core Preview 5? Not sure if this happens on Linux x64 as well. It didn’t happen on Windows x64 builds.
  4. Observe the exceptions being logged.

Notes

Will update once I try it with .NET Core 2.2.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
uwxcommented, Jun 6, 2019

I know what BindingFlags is, Einstein. I however did not (at the time of writing that code) know static constructors were treated the same as instance ones at runtime.

0reactions
red031000commented, Oct 20, 2019

while testing issue #477 I also came across a System.MemberAccessException on linux ARM64, by calling DiscordClient.GetGuildAsync, more info about my setup is in that issue.

full stack trace:

Type initializer was not callable.
   at System.Reflection.RuntimeConstructorInfo.ThrowNoInvokeException()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at DSharpPlus.Net.Serialization.SnowflakeArrayAsDictionaryJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, 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.CreateValueInternal(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.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at DSharpPlus.Net.DiscordApiClient.GetGuildAsync(UInt64 guildId)
   at DSharpPlus.DiscordClient.GetGuildAsync(UInt64 id)
   at StreamFeedBot.Utils.AnnounceMessage(String message, DiscordClient client) in D:\TwitchPlaysPokemon\StreamFeedBot\StreamFeedBot\Utils.cs:line 66
   at StreamFeedBot.Program.MainAsync() in D:\TwitchPlaysPokemon\StreamFeedBot\StreamFeedBot\Program.cs:line 169
   at StreamFeedBot.Program.Main() in D:\TwitchPlaysPokemon\StreamFeedBot\StreamFeedBot\Program.cs:line 50
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error on startup after upgrading from .Net Core 3.0 preview ...
1 Answer. Delete all previously published files (dlls are important to be deleted), upgrade all dependencies to previews for . net core 3.0...
Read more >
NET Core 3.0 Preview 1 makes app fail to start · Issue #5700
dotnet (start). Expected: app starts. Actual: exception is displayed. Application startup exception: System.InvalidOperationException: Scheme ...
Read more >
Breaking changes in .NET Core 3.0
Starting in ASP.NET Core 3.0 Preview 5, the fields in Microsoft.Net.Http.Headers.HeaderNames changed from const to static readonly .
Read more >
Announcing .NET Core 3.0 Preview 6
Today, we are announcing .NET Core 3.0 Preview 6. It includes updates for compiling assemblies for improved startup, optimizing applications ...
Read more >
ASP.NET Core 3.0 not showing on Visual Studio 2019
1- make sure Tools -> Options that enables preview versions of the .NET Core SDK enabled. 2- uninstall all x86 version of .net...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found