-
Notifications
You must be signed in to change notification settings - Fork 45
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
.NET dependencies resolving not working as expected #435
Comments
I got a workaround. It needs more tests and checks, maybe can cause other problems. But for now seems to work good. private static void ApplyAssemblyResolveFix(string searchDirectory)
{
AppDomain.CurrentDomain.AssemblyResolve += (object? sender, ResolveEventArgs args) =>
{
Debug.WriteLine($"Resolving assembly: {args.Name}");
var assemblyName = new AssemblyName(args.Name).Name;
var resolvedPath = Path.Combine(searchDirectory, $"{assemblyName}.dll");
if (File.Exists(resolvedPath))
{
Debug.WriteLine($"Resolved path: {resolvedPath}");
return Assembly.LoadFile(resolvedPath);
}
Debug.WriteLine("Not resolved.");
return null;
};
} Usage: public static void Main(string[] args)
{
var appDirPath = GetApplicationLocation();
ApplyAssemblyResolveFix(appDirPath);
//Use the library...
new GameModeBuilder()
.Use<GameMode>()
.Run();
}
private static string GetApplicationLocation()
{
var entryAssembly = Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Unable to determine the entry assembly.");
var appDirPath = Path.GetDirectoryName(entryAssembly.Location);
if (string.IsNullOrEmpty(appDirPath))
{
throw new InvalidOperationException("Unable to determine the application's location.");
}
return appDirPath;
} |
Check your package references. The versions in the package references for MS packages (eg. |
That seems to be a common mistake. Package version and target framework version seems to be independent.
|
Hi, seems there is a problem with dependency resolving when the application is run by SampSharp vs when is run directly.
The test case is with the nuget package
System.Text.Json
.If I try to use it running the server then I get an exception (details below), but if I run the program as console application then it works ok.
Exception:
Seems to be related to the library with the same name included in the .NET Core but it happens only with SampSharp.
I tested only on Windows.
NuGet package:
System.Text.Json 7.0.3
Test code:
• If I run as server without NuGet package: loaded correct version from
SERVER_FOLDER\dotnet\shared\Microsoft.NETCore.App\6.0.7\System.Text.Json.dll
• If I run as console app without NuGet package: loaded correct version from
C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\6.0.24\System.Text.Json.dll
• If I run as console app with NuGet package: loaded correct version from
SERVER_FOLDER\gamemode\Debug\net6.0\System.Text.Json.dll
• If I run as server with NuGet package: EXCEPTION!
What I tried:
copy
System.Text.Json.dll
toSERVER_FOLDER
: EXCEPTION!copy
System.Text.Json.dll
toSERVER_FOLDER\dotnet\shared\Microsoft.NETCore.App\6.0.7
: WORKED!Tried another package with no name conflict
Newtonsoft.Json 13.0.3
and it works ok in all cases.Seems when running SampSharp, it is trying to resolve the assemblies in wrong order paths, it seems that is checking the .NET libraries folders first.
The text was updated successfully, but these errors were encountered: