none
Embed assemblies inside another assembly RRS feed

  • Question

  • Hello all, 

    I'm trying to embed a dll within a class dll as an embedded resource rather than a reference. In another word, encapsulate another assembly within the assembly I'm writing. The goal is to be able to use method in the embedded assembly via the one I'm writing. Thus far, I have no success with StackOverFlow or any forums so I'm hoping someone can shed some light. Here is a snippet of what I have so far. 

    using System;
        using System.Runtime.InteropServices;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Drawing;
        using System.IO;
        using System.IO.Compression;
        using System.Web;
        using System.Diagnostics;
        using System.Reflection;
        using Aspose.Pdf;
        using Aspose.Pdf.Facades;
        using Aspose.Pdf.Text;
        using Aspose.Pdf.Generator;

    In my main method:

    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Resolver);

    Then:

    static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
            {
                Assembly asposePdf = Assembly.GetExecutingAssembly();
                Stream _asposePdf = asposePdf.GetManifestResourceStream(string.Format("Aspose.Pdf.dll"));
                byte[] assembly = new byte[_asposePdf.Length];
                _asposePdf.Read(assembly, 0, assembly.Length);
                Assembly a2 = Assembly.Load(assembly);
                return a2;
            }

    *The Aspose.Pdf.dll had been set as an Embedded Resource within the project.

    When build, I still get:

    The type or namespace name 'Aspose' could not be found (are you missing a using directive or an assembly reference?)

    Any help is appreciate. Thanks.

    Wednesday, November 16, 2016 10:40 PM

All replies

  • You still need to reference the assembly to get code to compile. You just don't need to copy the referenced dll to debug output. 


    Visual C++ MVP

    Wednesday, November 16, 2016 11:29 PM
  • Please try to add the assembly reference for the project, and when you run the program in the production, no need to copy the Aspose.Pdf.dll to the executable directory.
    Thursday, November 17, 2016 1:23 AM
  •  Hi N4K3,

    >>*The Aspose.Pdf.dll had been set as an Embedded Resource within the project.

    I've made a dll on my local side. It works fine. So I wonder if you haven't add your Aspose.Pdf.dll as an Embedded Resource successfully.

    So try to use the following code to check your embedded resource

      string[] aa=   Assembly.GetExecutingAssembly().GetManifestResourceNames();

    Note: when debugging. This will list all the (fully qualified names) of all resources embedded in the assembly your code is written in.

    Here is my screen capture.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Kristin Xie Thursday, December 1, 2016 7:57 AM
    Friday, November 18, 2016 3:14 AM
  • Dear N4K3,

    What's the problem now? Do you have any updates?

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 23, 2016 6:11 AM