none
Embedding few related dlls files into my class library project as a embedded resource & getting error - string reference not set to an instance of a string RRS feed

  • Question

  • this question is purely related to .net rather not about devexpress component. so please do not bypass. 

    i have install devexpress suit in my office pc and there i have created one class library project where i have refer few dll into that project.

    first i add all reference and then add those devex dll into a folder called Lib in my class library project and later i add those devex dll to my resource and change each dll to embed resource from property window.

    in my class library project i have one class which has one constructor from where i load those dll from resource. i used this code to do so.

    i followed this link https://c-sharplibrary.blogspot.com/2017/05/embed-one-dll-inside-another-as.html

    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>  
                    {  
                        string resourceName = new AssemblyName(args.Name).Name + ".dll";  
                        string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));  
          
                        using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))  
                        {  
                            Byte[] assemblyData = new Byte[stream.Length];  
                            stream.Read(assemblyData, 0, assemblyData.Length);  
                            return Assembly.Load(assemblyData);  
                        }  
                    };

    when i test this dll project in to my pc then it work because i have installed devex setup in my pc but when i run the same project from another pc 
    which has no devex installed and do not have devex license there i got a error.

    the error was ambiguous. error text was string reference not set to an instance of a string

    i really do not understand does this error throwing from devex component or can i embed devex dll as resource into another dll project ?

    from this below code a exception was throwing to calling environment. exception was string reference not set to an instance of a string

    anyone can tell me from which code or line suppose to throwing this exception called string reference not set to an instance of a string ?

    see my class library project code which is not big

    using System;  
        using System.Collections.Generic;  
        using System.Linq;  
        using System.IO;  
        using DevExpress.Spreadsheet;  
          
          
        namespace xExcel.Convertion  
        {  
            /// <summary>  
            /// Converter class will convert excel formatted values to actual values  
            /// </summary>  
            public class Converter  
            {  
                /// <summary>  
                /// Converter will load DevEx Assembly from resource  
                /// </summary>  
                public Converter()  
                {  
                    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>  
                    {  
                        string resourceName = new AssemblyName(args.Name).Name + ".dll";  
                        string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));  
          
                        using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))  
                        {  
                            Byte[] assemblyData = new Byte[stream.Length];  
                            stream.Read(assemblyData, 0, assemblyData.Length);  
                            return Assembly.Load(assemblyData);  
                        }  
                    };  
                }  
          
                private DevExpress.XtraSpreadsheet.SpreadsheetControl sscConverter;  
          
                public List<Status> Convert(string ExcelSourceFilePath, string ExcelSaveFilePath, List<string> ListOfSheets)  
                {  
                    List<Status> _status = null;  
          
                    #region Validating inputs  
          
                    if (ExcelSourceFilePath.Trim()=="")  
                    {  
                        throw new Exception("Source excel file path is empty");  
                    }  
          
                    if (ExcelSaveFilePath.Trim() == "")  
                    {  
                        throw new Exception("Save excel file path is empty");  
                    }  
          
                    if (ListOfSheets.Count <= 0)  
                    {  
                        throw new Exception("No Sheet / tab name found");  
                    }  
          
                    if (!File.Exists(ExcelSourceFilePath))  
                    {  
                        throw new FileNotFoundException("Source excel file not found " + ExcelSourceFilePath);  
                    }  
          
                    if (!Directory.Exists(ExcelSaveFilePath))  
                    {  
                        throw new FileNotFoundException("Excel Save path not found " + ExcelSaveFilePath);  
                    }  
                    #endregion  
          
                    #region convertion start  
                    if (ExcelSourceFilePath.Trim() != "" & ExcelSaveFilePath.Trim() != "")  
                    {  
                        int counter = 0;  
                        _status = new List<Status>();  
                        string strExt = "";  
                        string currentSheetName = "";  
          
                        // storing file extension  
                        strExt = Path.GetExtension(ExcelSourceFilePath).ToUpper();  
          
                        // checking list of sheet name exist or not  
                        if (ListOfSheets.Count > 0)  
                        {  
                            // if excel source file exist  
                            if (File.Exists(ExcelSourceFilePath))  
                            {  
                                sscConverter = new DevExpress.XtraSpreadsheet.SpreadsheetControl();  
          
                                // loading excel file into spread sheet  
                                sscConverter.LoadDocument(ExcelSourceFilePath);  
          
                                DevExpress.Spreadsheet.IWorkbook workbook = sscConverter.Document;  
          
                                try  
                                {  
                                    sscConverter.BeginUpdate();  
          
                                    // iterate in sheet collection  
                                    foreach (Worksheet sheet in workbook.Worksheets)  
                                    {  
                                        // if sheet name matched then clearing the format  
                                        if (ListOfSheets.Where(a => a.ToUpper() == sheet.Name.ToUpper()).Count() > 0)  
                                        {  
                                            currentSheetName = sheet.Name;  
          
                                            Range usedRange = sheet.GetUsedRange();  
                                            usedRange.ClearFormats();  
                                            // storing convertion status for reporting to client if passed  
                                            _status.Add(new Status { SheetName = currentSheetName, Success = true });  
                                            counter++;  
                                        }  
                                    }  
          
                                    sscConverter.EndUpdate();  
          
                                    if (counter > 0)  
                                    {  
                                        if (workbook != null)  
                                        {  
                                            // after convertion of mention sheets saving excel to new path  
                                            workbook.SaveDocument(ExcelSaveFilePath + "\\" + Path.GetFileName(ExcelSourceFilePath),  
                                                (strExt == ".XLSX" ? DevExpress.Spreadsheet.DocumentFormat.Xlsx : DevExpress.Spreadsheet.DocumentFormat.Xls));  
                                        }  
                                    }  
                                }  
                                catch (Exception ex)  
                                {  
                                    // storing convertion status for reporting to client if fail  
                                    _status.Add(new Status { SheetName = currentSheetName, Success = false });  
                                }  
                                finally  
                                {  
                                    sscConverter = null;  
                                }  
          
                            }  
                        }  
                    }  
                    #endregion  
          
                    // returning status to calling environment  
                    return _status;  
                }  
            }  
          
            /// <summary>  
            /// Status class will store the Excel sheet by sheet processing status  
            /// </summary>  
            public class Status  
            {  
                public string  SheetName { get; set; }  
                public bool Success { get; set; }  
            }  
        }

    I post this issue to devexpress forum and they said we can include their dll into my class library project as resource.

     they suggest me to post this issue in stackoverflow forum. here link where i have posted this issue https://www.devexpress.com/Support/Center/Question/Details/T758350/embedding-spread-sheet-related-dll-files-into-my-class-library-project-as-a-embedded

    please some one help me to catch this issue where the problem lies ?

    this question is purely related to .net not devexpress. 

    Wednesday, July 24, 2019 8:53 PM

All replies

  • Hi Sudip_inn,

    Thank you for posting here.

    I want to know how do you call DevExpress.Spreadsheet. what Nuget Packages you used? I could not find it, which makes me don't create a dll.

    I hope that you could tell me the above information.

    Best Regards,

    Jack


    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.

    Thursday, July 25, 2019 5:37 AM
    Moderator
  • i download their setup from their web site. when i install that setup there i need to give my register email id where license was issued. i did not download from nuget.

    tell me what more info i need to share with you. thanks

    • Edited by Sudip_inn Thursday, July 25, 2019 9:25 AM
    Thursday, July 25, 2019 9:24 AM
  • Hi Sudip_inn,

    Thanks for the feedback.

    >>when i test this dll project in to my pc then it work because i have installed devex setup in my pc but when i run the same project from another pc which has no devex installed and do not have devex license there i got a error.

    According to this sentence, I think whether you installed devex setup could be the reason of throwing exception.

    Since I could not test your code because of unknowing how to use DevExpress.Spreadsheet. Therefore, If you want to solve the problem, it is best for you to upload your project to OneDrive to share with us.

    Best Regards,

    Jack


    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.

    Friday, July 26, 2019 5:14 AM
    Moderator
  • sure i will try & let you know. thanks
    Friday, July 26, 2019 8:05 AM