MircoBabin / KeePassCommander

A KeePass plugin to provide a communication channel for PHP scripts, Windows CMD/BAT/PowerShell scripts, Python, C#, Lua, git, etc. to query the KeePass password store without requiring configuration or passwords.
Other
32 stars 7 forks source link

Doesn't work with a different KeePass version (2.45) #2

Closed gjf closed 2 years ago

gjf commented 5 years ago

This plugin simply doesn't work with KeePass 2.42. Please update it.

MircoBabin commented 5 years ago

I tested the plugin with KeePass 2.42 and everything functions normally.

Can you describe in more detail what isn't working ?

gjf commented 5 years ago

Безымянный

MircoBabin commented 5 years ago

What language is this message in ? Could provide a translation please ? I can't read this language.

gjf commented 5 years ago

Безымянный

MircoBabin commented 5 years ago

I have some additional questions:

1) What Windows version are you using ? (Windows/7, Windows/10, ...) 2) What .NET frameworks are installed ? (https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed)

gjf commented 5 years ago
  1. Win10 Pro x64 (1809)
  2. 4.7.03190
ejohnsonbegin commented 4 years ago

I got the same error, with the debugger I get:

{Unuable to load the file or assembly 'KeePass, Version=2.42.1.23464, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c' or one of the dependency. The specified file cannot be found.":{"KeePass, Version=2.42.1.23464, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c"}System.Exception System.IO.FileNotFoundException}

FusionLog\:

===Prior link status information ===
JRN : user = _____
JRN : DisplayName = KeePass, Version=2.42.1.23464, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c
 (Fully-specified)
JRN : Appbase = file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/
JRN : PrivatePath initial = NULL
Calling Assembly: KeePassCommander, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
===
JRN : this liaison start in the context of LoadFrom.
AVT : the native image will not be detected in the LoadFrom context. It will be only detected in the default loading context, like Assembly.Load().
JRN : no configuration file for the application has been found.
JRN : using machine configuration file C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
JRN : post-strategy reference : KeePass, Version=2.42.1.23464, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c
JRN : attempt to download the new URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/KeePass.DLL.
JRN : attempt to download the new URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/KeePass/KeePass.DLL.
JRN : attempt to download the new URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/KeePass.EXE.
AVT : the assembly name comparison caused the incompatibility: Secondary Version
JRN : attempt to download the new  URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/KeePass/KeePass.EXE.
JRN : attempt to download the new  URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/Plugins/KeePass.DLL.
JRN : attempt to download the new  URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/Plugins/KeePass/KeePass.DLL.
JRN : attempt to download the new  URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/Plugins/KeePass.EXE.
JRN : attempt to download the new  URL file:///D:/Downloads/KeePass-2.43-Source/Build/KeePass/Debug/Plugins/KeePass/KeePass.EXE.

Stacktrace:

   at System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName)
   at KeePass.Plugins.PluginManager.CreatePluginInstance(String strFilePath, String strTypeName) in D:\Downloads\KeePass-2.43-Source\KeePass\Plugins\PluginManager.cs:ligne 297

I have been able to temporarily correct the problem by re-adding the reference to keepass and rebuilding, but changing version of keepass still cause the problem.

MircoBabin commented 4 years ago

@ejohnsonbegin, thank you for the detailed report.

It looks like some kind of .NET dll-hell problem. I looked at KeePassHttp plugin and they are targetting .NET v4.

I have recompiled the plugin targetting.NET v4. Could you try this ? TestUsingDotNet4.zip

ejohnsonbegin commented 4 years ago

I think you will need to set Specific Version to false in the reference property and use the oldest supported keepass.exe as the reference hint. By referencing my installed 2.42, I was able to use it with the portable 2.43 the installed 2.42. If I was building by referencing 2.43, it wasn't working with 2.42. None were working with my custom build 2.43 because the PublicKeyToken wasn't matching.

diff --git a/src/KeePassCommanderPlugin/KeePassCommander.csproj b/src/KeePassCommanderPlugin/KeePassCommander.csproj
index e32ada5..f9978d8 100644
--- a/src/KeePassCommanderPlugin/KeePassCommander.csproj
+++ b/src/KeePassCommanderPlugin/KeePassCommander.csproj
@@ -31,7 +31,8 @@
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="KeePass">
      <HintPath>..\..\assets\KeePass.exe</HintPath>
+      <SpecificVersion>False</SpecificVersion>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
gjf commented 4 years ago

2.44 update - same issue.

MircoBabin commented 4 years ago

I have published Version 2.1 trying to address the problem with a different KeePass Version.

Version 2.1 is compiled against KeePass 2.44, so will work with KeePass 2.44. The question is: will it also work out of the box when KeePass 2.45 is released ?

gjf commented 4 years ago

MicroBabin, the answer is NO.

MircoBabin commented 4 years ago

@gjf

gjf commented 4 years ago

Безымянный It is official portable version running on Windows 10 Pro x64.

MircoBabin commented 4 years ago

Could you translate the following in English please ?

image

MircoBabin commented 4 years ago

@gjf

MircoBabin commented 4 years ago

@gjf Can you install https://github.com/awaescher/Fusion ?

There should be a failure visible. When you doubleclick the failure line a detailled log will be shown. Can you post this detailled log ?

gjf commented 4 years ago
  1. KeePass\Plugins\KeePassCommander
  2. Russian.lngx is placed into KeePass\Languages keepass.config.xml contains:
    <Application>
        <LanguageFile>Russian.lngx</LanguageFile>

It was set in GUI but stored in xml like all settings.

gjf commented 4 years ago

Pardon, I have no time to investigate it any further with every new update. Possibly someone else can do. Sorry about that.

MircoBabin commented 4 years ago

If anybody stumbles upon this problem, please run KeePass in debug mode and post the logfiles.

KeePass.exe --debug --KeePassCommanderDebug=c:\temp\KeePassCommander.log

lollita commented 4 years ago

When start show MessageBox:

OK C:\KeePass\Plugins\KeePassCommand\KeePassCommander.dll

Non è stato possibile caricare il file o l'assembly 'KeePass, Version=2.44.0.19625, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c' o una delle relative dipendenze. Impossibile trovare il file specificato. mscorlib in System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) in System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) in System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) in KeePass.Plugins.PluginManager.CreatePluginInstance(String strFilePath, String strTypeName) in KeePass.Plugins.PluginManager.LoadPlugins(List`1 lFiles, String strTypeName, String strDisplayFilePath, Boolean bSkipCacheFiles) Void GetType(System.Reflection.RuntimeAssembly, System.String, Boolean, Boolean, System.Runtime.CompilerServices.ObjectHandleOnStack)

ryivus commented 2 years ago

Hi, I did some digging and I think the only real issue is that the example project references the plugin files dynamically. At least it works for me fine using a newer version of KeePass after doing some small adjustments.

With the committed code everything works because there is also a KeePass version copied into the build output folder. So everything is in one place, assembly resolution is simple.

But when changing the location of the KeePassCommandDll.dll to a version installed at the regular KeePass .Net will dynamically load the KeePassCommandDll.dll just fine, BUT there is no override of the assembly resolution paths.

So by default the KeePass version copied to the build output folder is found and not the one located besides the dynamically loaded KeePassCommandDll.dll. This is prone to create issues.

To fix this either the assembly resolution event needs to be overridden or (much simpler) the dynamic loading of KeePassCommandDll.dll can be replaced by a simple project reference.

Then the complete example reduces to a one-liner: KeePassCommandDll.Api.getfirst(title);

Maybe this helps.

MircoBabin commented 2 years ago

@ryivus that's also a solution. But often the place of KeePassCommandDll.dll is not in the same directory as your executable. That's why it's dynamically loaded, to prevent startup errors because a referenced dll was not found.

This issue was about KeePass not starting, reporting errors because of the KeePassCommander.dll conflicting in some way with the KeePass and .NET framework versions.

Because this issue has been stale for a year now. I'm going to close it.