Embedded References Issue  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Embedded References Issue

Postby SBarnes » Sun Dec 17, 2017 9:31 am

Hi Mike,

I am getting an issue with an embedded reference DLL, namely Restsharp version 105.2.2.0, which when the plugin compiles everything is fine, the DLL is copied down to the compile directory under "C:\ProgramData\Jiwa Financials\Jiwa 7\" but it never makes it to the run time directory.

If I copy the DLL from compile to run time whilst Jiwa is running everything works perfectly but if you don't you get an error about not being able to find the reference, this happens under both 7.0.157 and 7.1 and on different databases of Jiwa demo, do you have any ideas as to why the DLL might not be making it to the run time directory and how to get around it besides dropping it in Jiwa's program directory?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Embedded References Issue

Postby Mike.Sheen » Sun Dec 17, 2017 12:47 pm

Hi Stuart,

Actually the embedded references are picked up from the Compilation folder - e.g.: C:\ProgramData\Jiwa Financials\Jiwa 7\7.1.0\mikes\localhost\JiwaDemo710\Plugins\Admin\Compile\Xero Cash Book Import

Have a look in there and see if the assembly is present there.

One way to troubleshoot this is to log Fusion's assembly resolution using Fuslogvw.

Run Fuslogvw and then log into Jiwa - you should see how Fusion is attempting to resolve the assembly - it should give a clue as to why it's not being resolved.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Embedded References Issue

Postby SBarnes » Sun Dec 17, 2017 3:08 pm

Hi Mike,

The files were in the compilation directory, that's where I was copying them from to the run time, the log which follows (thanks for the tip about the tool by the way) shows where the files are being looked for in that directory, I even cut and pasted the directory path from the log and put it in the windows run dialog and explorer shows a window with the DLLs present.

I have even confirmed the DLLs will work under 32 bit in a stand alone exe just to confirm that's not the issue of 64 bit vs 32 bit.

Do you have any other ideas?

Code: Select all
*** Assembly Binder Log Entry  (17/12/2017 @ 2:39:41 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Jiwa.exe
--- A detailed error log follows.

LOG: IJW explicit bind. File path:C:\ProgramData\Jiwa Financials\Jiwa 7\7.0.157\SBarnes\ENTERPRISE\JiwaDemo7\Plugins\Admin\Compile\Attkey Harvest\RestSharp.dll.
LOG: IJW assembly bind returned file not found.

*** Assembly Binder Log Entry  (17/12/2017 @ 2:39:41 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Jiwa.exe
--- A detailed error log follows.

LOG: IJW explicit bind. File path:C:\ProgramData\Jiwa Financials\Jiwa 7\7.0.157\SBarnes\ENTERPRISE\JiwaDemo7\Plugins\Admin\Compile\Attkey Harvest\RestSharp.dll.
LOG: IJW assembly bind returned file not found.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Embedded References Issue

Postby Mike.Sheen » Sun Dec 17, 2017 3:32 pm

SBarnes wrote:Do you have any other ideas?


Either post here or email me a plugin which exhibits the issue and I'll be able to work it out.

I suspect it's something quirky with the Assembly - we had that with one of the ServiceStack assemblies at one point, so we resorted to deploying those with the application - it was something to do with signed assemblies in that case.

For reference, this is the code we use to attempt to resolve embedded references:
Code: Select all
Public Sub ResolveReference()
   If EmbeddedReferenceCollection IsNot Nothing AndAlso EmbeddedReferenceCollection.Plugin IsNot Nothing Then
      Try
         ' Extract binary to plugin location                   
         ' It is possible the folder we need to write to does not exist yet - so we may need to create it first.
         If System.IO.Directory.Exists(EmbeddedReferenceCollection.Plugin.CompilationFolder) = False Then
            System.IO.Directory.CreateDirectory(EmbeddedReferenceCollection.Plugin.CompilationFolder)
         End If

         Dim pathAndFileName As String = System.IO.Path.Combine(EmbeddedReferenceCollection.Plugin.CompilationFolder, AssemblyName)

         Dim FileStream As System.IO.FileStream = Nothing

         Try
            If System.IO.File.Exists(pathAndFileName) Then
               System.IO.File.Delete(pathAndFileName)
            End If

            FileStream = New System.IO.FileStream(pathAndFileName, System.IO.FileMode.Create)
            FileStream.Write(FileBinary, 0, FileBinary.Length)
         Catch fileWriteException As Exception
            'Debug.WriteLine(fileWriteException.Message)
         Finally
            If Not FileStream Is Nothing Then
               FileStream.Flush()
               FileStream.Close()
            End If
         End Try

         If System.IO.File.Exists(pathAndFileName) Then
            Dim Assembly As System.Reflection.Assembly
            Assembly = System.Reflection.Assembly.LoadFile(pathAndFileName)
            Assembly = System.Reflection.Assembly.Load(Assembly.FullName) ' Need to load using FullName otherwise we might get an exception on GetCustomAttribute further down in this method

            AssemblyName = Assembly.ManifestModule.Name
            _AssemblyLocation = Assembly.Location
            _RuntimeVersion = Assembly.ImageRuntimeVersion
            _AssemblyFullName = Assembly.FullName

            Resolved = True

            Try
               Dim objDescriptionAttribute As System.Reflection.AssemblyDescriptionAttribute = System.Reflection.AssemblyDescriptionAttribute.GetCustomAttribute(Assembly, GetType(System.Reflection.AssemblyDescriptionAttribute))
               If Not objDescriptionAttribute Is Nothing Then
                  _Description = objDescriptionAttribute.Description
               End If

               Dim objVersionAttribute As System.Reflection.AssemblyFileVersionAttribute = System.Reflection.AssemblyFileVersionAttribute.GetCustomAttribute(Assembly, GetType(System.Reflection.AssemblyFileVersionAttribute))
               If Not (objVersionAttribute Is Nothing) Then
                  _FileVersion = objVersionAttribute.Version
               End If
            Catch metaDataException As Exception
               ' swallow
               'Console.WriteLine(metaDataException.Message)
            End Try
         End If

      Catch ex As Exception
         ' swallow failures to resolve
         _AssemblyFullName = ex.Message
      End Try
   End If
End Sub


I'm really leaning now towards providing the debug symbols for our assemblies to assist developers with these kind of issues.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Embedded References Issue  Topic is solved

Postby Mike.Sheen » Sun Dec 17, 2017 5:29 pm

The OP (Stuart) emailed me a plugin demonstrating the issue - to which I responded - and whilst I don't yet have a fix, for those coming across this topic with a similar issue, a workaround is to intercept the Assembly resolution in Jiwa by adding a handler in the ApplicationManagerPlugin class:

Code: Select all
public class ApplicationManagerPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaApplicationManagerPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
         JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.AssemblyResolveBefore += AssemblyResolveBefore;
    }
     
    public void AssemblyResolveBefore(object sender , System.ResolveEventArgs args, ref System.Reflection.Assembly assembly)
    {
        if (args.Name == "RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null")
        {
             // manually resolve assembly location
             assembly = System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.PluginFolder, @"Compile\<Plugin Name>\<Assembly Name>.dll"));
         }
    }
}



replace the <Plugin Name> and <Assembly Name> in the above to be your plugin name and the name of the embedded assembly, and also the "args.Name ==" to compare with the Assembly FullName to check for.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 25 guests

cron