tumtumtum / Shaolinq

ORM for .NET with full LINQ support for Postgres, Sqlite, MySql and SqlServer
Other
127 stars 19 forks source link

Exception has occurred: CLR/System.IO.FileLoadException #92

Closed hbjydev closed 5 years ago

hbjydev commented 5 years ago

So I'm making a Discord bot using this ORM, with this code:

using Shaolinq;
using Shaolinq.Postgres;

namespace ZshBot.Database
{
    public class Connection
    {
        public Connection(string connectionString)
        {
            var configuration = PostgresConfiguration.Create(connectionString);
            var model = DataAccessModel.BuildDataAccessModel<Models.TagModel>(configuration);

            model.Create(DatabaseCreationOptions.IfDatabaseNotExist);
        }
    }
}

...calling it in Program.cs like this...

...
else if (
                !Helpers.DoesEnvironmentVariableExist("DB_HOST", EnvironmentVariableTarget.Process) ||
                !Helpers.DoesEnvironmentVariableExist("DB_PORT", EnvironmentVariableTarget.Process) ||
                !Helpers.DoesEnvironmentVariableExist("DB_NAME", EnvironmentVariableTarget.Process) ||
                !Helpers.DoesEnvironmentVariableExist("DB_USER", EnvironmentVariableTarget.Process) ||
                !Helpers.DoesEnvironmentVariableExist("DB_PASS", EnvironmentVariableTarget.Process)
            )
            {
                var dbHost = "localhost";
                var dbPort = 5432;
                var dbName = "zshbot";
                var dbUser = "postgres";
                var dbPass = "";

                _connection = new Connection($"User ID={dbUser};Password={dbPass};Host={dbHost};Port{dbPort};Database={dbName}".ToString());
            }
            else
            {
                _token = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
                var dbHost = Environment.GetEnvironmentVariable("DB_HOST");
                var dbPort = int.Parse(Environment.GetEnvironmentVariable("DB_PORT"));
                var dbName = Environment.GetEnvironmentVariable("DB_NAME");
                var dbUser = Environment.GetEnvironmentVariable("DB_USER");
                var dbPass = Environment.GetEnvironmentVariable("DB_PASS");

                _connection = new Connection($"User ID={dbUser};Password={dbPass};Host={dbHost};Port{dbPort};Database={dbName}");
            }
...

...and I get this error when trying to start it up.

An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Private.CoreLib.dll: 'Could not load file or assembly 'Platform, Version=1.2.5.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
hbjydev commented 5 years ago

Full traceback and error as reported by my editor:

Exception has occurred: CLR/System.IO.FileLoadException
An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Private.CoreLib.dll: 'Could not load file or assembly 'Platform, Version=1.2.5.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
   at Shaolinq.DataAccessModelConfiguration..ctor()
   at Shaolinq.Postgres.PostgresConfiguration.Create(String connectionString)
   at ZshBot.Database.Connection..ctor(String connectionString) in /home/hayden/ZSHBot/ZshBot/Database/Connection.cs:line 10
   at ZshBot.Program.<MainAsync>d__5.MoveNext() in /home/hayden/ZSHBot/ZshBot/Program.cs:line 42
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ZshBot.Program.Main(String[] args) in /home/hayden/ZSHBot/ZshBot/Program.cs:line 19
tumtumtum commented 5 years ago

Hey! Make sure you have Platform.NET installed as well: https://www.nuget.org/packages/Platform.NET/

hbjydev commented 5 years ago

I just ran dotnet add ZshBot/ZshBot.csproj package Platform.NET and tried re-running, but I got the same error.

hbjydev commented 5 years ago

Oh, hang on, it's not the same error.

Exception has occurred: CLR/System.IO.FileLoadException
An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Private.CoreLib.dll: 'Could not load file or assembly 'Platform.Xml.Serialization, Version=1.2.5.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
   at Shaolinq.TypeBuilding.CachingDataAccessModelAssemblyProvider.AssemblyKey..ctor(Type dataAccessModelType, DataAccessModelConfigurationUniqueKey configurationUniqueKey)
   at Shaolinq.TypeBuilding.CachingDataAccessModelAssemblyProvider.GetDataAccessModelAssembly(Type dataAccessModelType, DataAccessModelConfiguration configuration)
   at Shaolinq.DataAccessModel.BuildDataAccessModel(Type dataAccessModelType, DataAccessModelConfiguration configuration)
   at Shaolinq.DataAccessModel.BuildDataAccessModel[T](DataAccessModelConfiguration configuration)
   at ZshBot.Database.Connection..ctor(String connectionString) in /home/hayden/ZSHBot/ZshBot/Database/Connection.cs:line 11
   at ZshBot.Program.<MainAsync>d__5.MoveNext() in /home/hayden/ZSHBot/ZshBot/Program.cs:line 42
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ZshBot.Program.Main(String[] args) in /home/hayden/ZSHBot/ZshBot/Program.cs:line 19
tumtumtum commented 5 years ago

You'll want this package too: https://www.nuget.org/packages/Platform.Xml.Serialization/