Include Dll Aspose Word into my library

I’ve made a Library in vb.net. This library include Aspose Words.
the 1st time just include “Aspose.Words.dll” as reference.
Imports Aspose.words in my file, example my module
Make some function and use normaly document transformation Document builder …
and return result

Generate my projet : Ok, i’ve got 2 files :

  • myProject.dll
  • Aspose.words.dll

But i’ve got a problem when send it to my colleague, he’s say me he must add only 1 dll. because his projects use diffrents versions of aspose.words
My dll must include others dll.
i’ve find some sample on the web to embed dll as resource but how to use them in differents functions, class, methods… ? can’t add imports, i’ve got no main function to load assemblies

Example EmbeddedAssembly

Thanks.

@conan76 this is out of Aspose forum scope. Additionally if you want to work with DLL as resource, you can use the following tips:

  1. Add the dependency DLL to your project’s resources by right-clicking on your project in the Solution Explorer, selecting “Properties”, and then selecting the “Resources” tab. From there, select “Add Resource” -> “Add Existing File” and browse to the location of your dependency DLL. Select the DLL and click “Add” (I assuming you are using Visual Studio).
  2. In your VB.NET code, you can load the embedded DLL using the LoadLibrary function. Here’s an example:
Module EmbeddedDllLoader

    Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As IntPtr

    Public Function LoadEmbeddedDll(ByVal resourceName As String) As IntPtr
        Dim assembly As Assembly = Assembly.GetExecutingAssembly()
        Dim resourceStream As System.IO.Stream = assembly.GetManifestResourceStream(resourceName)

        Dim size As Integer = CInt(resourceStream.Length)
        Dim buffer(size - 1) As Byte
        resourceStream.Read(buffer, 0, size)

        Dim tempFileName As String = System.IO.Path.GetTempFileName()
        Dim fs As New System.IO.FileStream(tempFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)
        fs.Write(buffer, 0, size)
        fs.Close()

        Dim handle As IntPtr = LoadLibrary(tempFileName)

        System.IO.File.Delete(tempFileName)

        Return handle
    End Function

End Module

This code defines a function LoadEmbeddedDll that takes the name of the embedded resource containing the dependency DLL and returns an IntPtr handle to the loaded DLL.

Note that this code first saves the embedded DLL to a temporary file on disk, and then loads that file using the LoadLibrary function. This is necessary because LoadLibrary cannot directly load an embedded resource. Once the DLL is loaded, the temporary file is deleted.

To use this function, you can call it like this:

Dim dllHandle As IntPtr = LoadEmbeddedDll("MyProject.MyDependency.dll")

Replace "MyProject.MyDependency.dll" with the name of the embedded resource that contains your dependency DLL. You can find the name of the embedded resource by looking at the resources in your project’s Properties window.

Once you have the handle to the loaded DLL, you can use it to call functions from the DLL using the DllImport attribute and the Declare statement, just as you would with a regular external DLL.

Ok,

for example, if i want use this for 3 dll :
Aspose.words
Apose.Pdf
NewtonSoft.Json

i’ve must add 3 variables ?

i need callLoadEmbeddedDll function to all call ?

becase this my library is implemented on web site project (example web site to upload a pdf file)

my project generate a doc for the first page (with doc template) document builder…etc…
Convert this to PDF and add uploaded document to my document.

And my project connect to a service provider (rexdoc.fr) and submits the document PDF, which returns an identifier.

I’ve made a test with embeded aspose.pdf and i’ve got an reference error on website implement my dll :

image.png (59,2 Ko)

@conan76 as I said this is out of the scope of this forum, you probably need to post your query in a VB forum.

i’ve must add 3 variables ?

Yes, 1 for each DLL that you want to load.

i need callLoadEmbeddedDll function to all call ?

Not sure about what you are querying, but when you load dynamically a DLL from a resource file it usually is done in the app start and stored in a Singleton.

I’ve made a test with embeded aspose.pdf and i’ve got an reference error on website implement my dll

Without review your whole Solution will be hard to me determine what’s the cause of the issue, but it could be the lost of reference. Also, notice that the code that I provide (which is one of several possible solution) uses Reflection to load the package, this mean that the dependency will no be available until runtime (in compile time those references will not exists and you should find a way to deal with it in your development environment).
To be honest the safest and easiest way to add Aspose references to your project is using the NuGet Package, notice that you also can embed all your project references in your own generated DLL.