Jump to content

Recommended Posts

Posted (edited)

Hello, i run into some error with my code, do someone have a idea to fix it?
 

Could not load file or assembly 'C:\GrandRP Launcher\RAGEMP\server-files\dotnet\resources\Core\bin\Debug\net6.0\System.Data.Common.dll'.
Could not load file or assembly 'System.Data.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

They say "No such file". I tried with copy and paste the dll to the Debug net folder but nothing seems to be fixed :( 
 

using GTANetworkAPI;
using MySqlConnector;

namespace Core
{
    public class MainClass : Script
    {

        [ServerEvent(Event.PlayerConnected)]
        public void onPlayerConnected(Player player)
        {
            if (!playerExistsInDb(player))
            {
                NAPI.Util.ConsoleOutput("No player found");
            }
        }

        public bool playerExistsInDb(Player player)
        {
            using (MySqlConnection connection = new MySqlConnection("***"))
            {
                connection.Open();
                MySqlCommand command = connection.CreateCommand();

                command.CommandText = "SELECT count(*) AS count FROM `players` WHERE scID = @id";
                command.Parameters.AddWithValue("@id", player.SocialClubId);

                bool playerExists = false;
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        if (reader.GetInt64("count") > 0)
                        {
                            playerExists = true;
                        }
                    }
                }

                connection.Close();
                return playerExists;
            }
        }
    }
}

My hole script, hope someone can help me! 
Greetings :D

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
	<PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Bootstrapper">
      <HintPath>..\..\runtime\Bootstrapper.dll</HintPath>
    </Reference>
    <Reference Include="MySqlConnector">
      <HintPath>..\..\runtime\MySqlConnector.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>

My .csproj if needed

 

Edited by CorruptedVeit
  • CorruptedVeit changed the title to [C#] Could not load file or assembly
Posted

You need to copy dll file to runtime folder

C:\GrandRP Launcher\RAGEMP\server-files\dotnet\resources\Core\bin\Debug\net6.0\System.Data.Common.dll

Copy System.Data.Common.dll to C:\GrandRP Launcher\RAGEMP\server-files\dotnet\runtime

Posted (edited)
vor 5 Stunden schrieb LightScr:

You need to copy dll file to runtime folder

C:\GrandRP Launcher\RAGEMP\server-files\dotnet\resources\Core\bin\Debug\net6.0\System.Data.Common.dll

Copy System.Data.Common.dll to C:\GrandRP Launcher\RAGEMP\server-files\dotnet\runtime

This works for me, i copied the System.Data.Common to the net6.0 folder but now i got the error
 

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 

System.Diagnostics.DiagnosticSource is in both folders

Edited by CorruptedVeit
Posted

Maybe you need to copy System.IO.dll? Also I would recommend to create postbuild script which will copy DLLs after every build.

Add this to your projectName.csproj before </Project>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
    <Exec Command="call postbuild.bat $(ConfigurationName)" />
</Target>

in the same folder create file and adjust my script to your needs - postbuild.bat

echo Build type: %1

cd /d %~dp0 
xcopy bin\%1\netcoreapp3.1\en-GB ..\..\runtime\en-GB /e /i /Y
xcopy bin\%1\netcoreapp3.1\en-GB bin\%1\netcoreapp3.1 /e /i /Y

copy bin\%1\netcoreapp3.1\Microsoft.Extensions.DependencyInjection.Abstractions.dll ..\..\runtime\Microsoft.Extensions.DependencyInjection.Abstractions.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.DependencyInjection.dll ..\..\runtime\Microsoft.Extensions.DependencyInjection.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Logging.Abstractions.dll ..\..\runtime\Microsoft.Extensions.Logging.Abstractions.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Logging.dll ..\..\runtime\Microsoft.Extensions.Logging.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Caching.Abstractions.dll ..\..\runtime\Microsoft.Extensions.Caching.Abstractions.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Options.dll ..\..\runtime\Microsoft.Extensions.Options.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Caching.Memory.dll ..\..\runtime\Microsoft.Extensions.Caching.Memory.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Primitives.dll ..\..\runtime\Microsoft.Extensions.Primitives.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Bcl.HashCode.dll ..\..\runtime\Microsoft.Bcl.HashCode.dll /Y
copy bin\%1\netcoreapp3.1\Pomelo.JsonObject.dll ..\..\runtime\Pomelo.JsonObject.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.Extensions.Configuration.Abstractions.dll ..\..\runtime\Microsoft.Extensions.Configuration.Abstractions.dll /Y

copy bin\%1\netcoreapp3.1\System.ComponentModel.Annotations.dll ..\..\runtime\System.ComponentModel.Annotations.dll /Y
copy bin\%1\netcoreapp3.1\System.Diagnostics.DiagnosticSource.dll ..\..\runtime\System.Diagnostics.DiagnosticSource.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.EntityFrameworkCore.dll ..\..\runtime\Microsoft.EntityFrameworkCore.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.EntityFrameworkCore.Relational.dll ..\..\runtime\Microsoft.EntityFrameworkCore.Relational.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.EntityFrameworkCore.Abstractions.dll ..\..\runtime\Microsoft.EntityFrameworkCore.Abstractions.dll /Y
copy bin\%1\netcoreapp3.1\Microsoft.EntityFrameworkCore.Design.dll ..\..\runtime\Microsoft.EntityFrameworkCore.Design.dll /Y
copy bin\%1\netcoreapp3.1\MySqlConnector.dll ..\..\runtime\MySqlConnector.dll /Y
copy bin\%1\netcoreapp3.1\Pomelo.EntityFrameworkCore.MySql.dll ..\..\runtime\Pomelo.EntityFrameworkCore.MySql.dll /Y
copy bin\%1\netcoreapp3.1\Newtonsoft.Json.dll ..\..\runtime\Newtonsoft.Json.dll /Y
EXIT /B 0

 

Posted

Inside your <PropertyGroup> tag in .csproj add this:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

 

If you are using .NET 6.0 try with .NET 3.1 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...