[Bug] .NET 10 String sourcePlayer passed in Natives broken #121
Replies: 3 comments 5 replies
|
Workaround: The value returned by [FromSource] string sourcePlayer is in the format internal-net: (e.g. internal-net:1). Native functions such as GetNumPlayerIdentifiers and GetPlayerIdentifierByType expect only the numeric player source (e.g. 1). Stripping everything before the : allows these natives to work correctly. Ideally, [FromSource] should either return the native player source directly or the native APIs should accept the internal-net: format consistently. Here is some code example: [OnEvent("playerConnecting")]
public async Task OnPlayerConnecting(
[FromSource] string sourcePlayer,
string playerName,
Action<string> setKickReason,
IDictionary<string, FunctionReference> connectionDeferrals)
{
try
{
// Workaround:
// [FromSource] returns values such as "internal-net:1" instead of the
// native player source ("1"). Native functions like
// GetNumPlayerIdentifiers/GetPlayerIdentifierByType expect only the
// numeric source ID, so strip the "internal-net:" prefix first.
var separatorIndex = sourcePlayer.IndexOf(':');
var nativeSource = separatorIndex >= 0
? sourcePlayer[(separatorIndex + 1)..]
: sourcePlayer;
API.Log.Info($"{playerName} ({sourcePlayer}) connecting");
Console.WriteLine($"Managed source: {sourcePlayer}");
Console.WriteLine($"Native source: {nativeSource}");
var identifierCount = Native.GetNumPlayerIdentifiers(nativeSource);
Console.WriteLine($"Identifier count: {identifierCount}");
var discordIdentifier = Native.GetPlayerIdentifierByType(nativeSource, "discord");
Console.WriteLine($"Discord identifier: {discordIdentifier}");
connectionDeferrals["update"].CallVoid($"Welcome, {playerName}!");
await API.Delay(500);
connectionDeferrals["done"].CallVoid();
}
catch (Exception ex)
{
API.Log.Error($"Error handling connection for {playerName}: {ex}");
connectionDeferrals["done"].CallVoid("An internal error occurred while processing your connection.");
}
} |
|
Hey! Sorry for a rather late response on this. [FromSource] attribute injects source depending on the argument type. If you request |
|
A fix for this bug has been implemented and is available in the latest patch b96/97. Please try again and let us know if the issue persists. Thanks for your help! |



Uh oh!
There was an error while loading. Please reload this page.
Summary
[FromSource] string from playerConnecting cannot be used with native methods that expect a player source string.
I'm not sure if this has already been reported, but I noticed an inconsistency with the new .NET runtime.
In the playerConnecting event, the player source is exposed as:
[FromSource] string sourcePlayer
Several native methods (such as GetNumPlayerIdentifiers and GetPlayerIdentifierByType) also accept a string representing the player source, so I expected the value provided by [FromSource] to work directly with these methods.
For example:
The sourcePlayer value is printed correctly, but passing it to native methods such as GetNumPlayerIdentifiers or GetPlayerIdentifierByType causes the server to throw an exception.
Expected behavior
The value received from [FromSource] string sourcePlayer should be directly usable with native methods that accept a player source as a string, such as:
Native.GetNumPlayerIdentifiers(sourcePlayer)
Native.GetPlayerIdentifierByType(sourcePlayer, "discord")
Actual behavior
Passing the value obtained from [FromSource] into these native methods throws an exception on the server.
This makes it unclear whether:
the value provided by [FromSource] is not the expected player source,
the native method signatures are incorrect,
or an internal conversion is missing.
If [FromSource] string is intended to represent the player's server ID, it should be accepted by these native methods without throwing.
Here is exact error:
Issue type
Server
Repro rate
Always
Server build version
FXServer-early-access b93 win32
OS
No response
CPU
No response
GPU
No response
RAM
No response
Storage type
None
Connection type
None
ISP and bandwidth
No response
DxDiag
No response
Network graph
No response
Platform
Windows
OS version / distribution
Windows 11
CPU
No response
RAM
No response
Using txAdmin?
Yes
Hosting provider
None
Machine type
None
/perf endpoint output
No response
DDoS protection
No response
ulimit -n value (Linux only)
No response
Docker Compose file (Docker only)
No response
Steps to Reproduce
Expected Behavior
No exception should be thrown.
Actual Behavior
Exception thrown.
Evidence
Additional Context
No response
All reactions