Skip to content
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

Could not load file or assembly 'RepoDb.PostgreSql.dll' #1040

Closed
Swoorup opened this issue Mar 4, 2022 · 7 comments
Closed

Could not load file or assembly 'RepoDb.PostgreSql.dll' #1040

Swoorup opened this issue Mar 4, 2022 · 7 comments
Assignees
Labels
bug Something isn't working fixed The bug, issue, incident has been fixed. todo Things to be done in the future

Comments

@Swoorup
Copy link
Contributor

Swoorup commented Mar 4, 2022

Bug Description

When launching a dotnet executable using dotnet run -- -c appsettings.json from a project directory, it no longer finds RepoDb.PostgreSql

Exception Message:

System.AggregateException: One or more errors occurred. (Could not load file or assembly '/Users/swoorup.joshi/work/gp-suburb-api/src/WebApi/RepoDb.PostgreSql.dll'. The system cannot find the file specified.
)
 ---> System.IO.FileNotFoundException: Could not load file or assembly '/Users/swoorup.joshi/work/gp-suburb-api/src/WebApi/RepoDb.PostgreSql.dll'. The system cannot find the file specified.

File name: '/Users/swoorup.joshi/work/gp-suburb-api/src/WebApi/RepoDb.PostgreSql.dll'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at RepoDb.Reflection.Compiler.GetSetToUnknownNpgsqlParameterExpression(ParameterExpression commandParameterExpression, DbField dbField)
   at RepoDb.Reflection.Compiler.GetDataEntityParameterAssignmentExpression(ParameterExpression commandParameterExpression, Int32 entityIndex, Expression entityExpression, ParameterExpression propertyExpression, DbField dbField, ClassProperty classProperty, ParameterDirection direction, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetPropertyFieldExpression(ParameterExpression commandParameterExpression, Expression entityExpression, FieldDirection fieldDirection, Int32 entityIndex, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.GetIndexDbParameterSetterExpression(Type entityType, ParameterExpression commandParameterExpression, Expression entitiesParameterExpression, IEnumerable`1 fieldDirections, Int32 entityIndex, IDbSetting dbSetting)
   at RepoDb.Reflection.Compiler.CompileDataEntityListDbParameterSetter(Type entityType, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.Reflection.FunctionFactory.CompileDataEntityListDbParameterSetter(Type entityType, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.FunctionCache.DataEntityListDbParameterSetterCache.Get(Type entityType, String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.FunctionCache.GetDataEntityListDbParameterSetterCompiledFunction(Type entityType, String cacheKey, IEnumerable`1 inputFields, IEnumerable`1 outputFields, Int32 batchSize, IDbSetting dbSetting)
   at RepoDb.Contexts.Providers.MergeAllExecutionContextProvider.CreateInternal(Type entityType, IDbConnection connection, IEnumerable`1 entities, IEnumerable`1 dbFields, String tableName, IEnumerable`1 qualifiers, Int32 batchSize, IEnumerable`1 fields, String commandText)
   at RepoDb.Contexts.Providers.MergeAllExecutionContextProvider.CreateAsync(Type entityType, IDbConnection connection, IEnumerable`1 entities, String tableName, IEnumerable`1 qualifiers, Int32 batchSize, IEnumerable`1 fields, String hints, IDbTransaction transaction, IStatementBuilder statementBuilder, CancellationToken cancellationToken)
   at RepoDb.DbConnectionExtension.MergeAllAsyncInternalBase[TEntity](IDbConnection connection, String tableName, IEnumerable`1 entities, IEnumerable`1 qualifiers, Int32 batchSize, IEnumerable`1 fields, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder, CancellationToken cancellationToken)
   at RepoDb.DbConnectionExte

Library Version:

Example: RepoDb 1.12.10 and RepoDb.PostgreSql 1.1.5

@Swoorup Swoorup added the bug Something isn't working label Mar 4, 2022
@mikependon
Copy link
Owner

@Swoorup I think, I have made an explanation to this in the gitter chat in the past. Is this issue still necessary to be fixed? Please advise as we are now moving towards the new release.

@Swoorup
Copy link
Contributor Author

Swoorup commented Sep 5, 2022

@mikependon Is it possible to add ${workingDirectory}/bin/${Configuration}/${targetFramework}/ to the search path of the dll?

I think it's common to launch projects from directory using dotnet run which contains the project csproj or fsproj file using dotnet, but dlls are in those bin/{debug/release} folder.

@jbrezina
Copy link

@mikependon can you, please describe the issue also here? I think we still need the fix as we cannot debug the project with VisualStudio right now..

@mikependon mikependon added the todo Things to be done in the future label Jan 16, 2023
@mikependon
Copy link
Owner

@jbrezina sure.

@mikependon can you, please describe the issue also here? I think we still need the fix as we cannot debug the project with VisualStudio right now..

The main reason to this is the fact that RepoDb.dll is loading the RepoDb.PostgreSql.dll on-the-fly before generating an AOT compilation of the code itself. That process is failing if the RepoDb.PostgreSql.dll is not placed where the RepoDb.dll is located. This only happens when you manually run the solution, not when you are running the built/compiled solution.

Why on-the-fly loading? It is because that RepoDb.dll is a core and is the base of everything, whilst RepoDb.PostgreSql.dll is just an extension and is not directly referenced by the core (it is the other way around).

@jbrezina
Copy link

jbrezina commented Jan 16, 2023

I think the source directory is not read correctly as the RepoDb.PostgreSql.dll library is trying to be loaded from the project directory and not the bin directory. I can see both libraries are located in the same (bin) directory.

edit: I can see that there is no path given to the library, could you use something like AppDomain.BaseDirectory to build the path to the library? Or something like AsseblyLoadContext? Or any other method to get the exact location of the file?
By default, the working directory in VisualStudio is set to the project directory, not the binaries directory so it is not possible to load the library while debugging the project within VisualStudio.

@anpin
Copy link
Contributor

anpin commented Mar 10, 2023

this is quite annoying as it breaks dotnet watch

@mikependon mikependon pinned this issue Mar 10, 2023
mikependon added a commit that referenced this issue Mar 13, 2023
Fixes to the #1040 | Integration Tests | IDbHelper.DynamicHandler
@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Mar 13, 2023
@mikependon
Copy link
Owner

mikependon commented Mar 13, 2023

In the fixes, we have completely eliminated the dynamic loading of the extended library. To resolved the issue, we have extended the IDbHelper object with the DynamicHandler method and used that as a passthrough method when passing a notification between the core library and extended library.

The fixes to this will be available in the next version of the library >= v1.13.1-alpha2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed The bug, issue, incident has been fixed. todo Things to be done in the future
Projects
None yet
Development

No branches or pull requests

4 participants