Starting my programm on a Diffrent PC i get a error message

C# .NET WindowsForms - running application

Error Message:

System.IO.FileNotFoundException: Could not load file or assembly ‘GemBox.Spreadsheet, Version=49.0.0.1274, Culture=neutral, PublicKeyToken=b1b72c69714d4847’ or one of its dependencies. The system cannot find the file specified.
File name: ‘GemBox.Spreadsheet, Version=49.0.0.1274, Culture=neutral, PublicKeyToken=b1b72c69714d4847’
at Update_Report.Form4.Form4_Load(Object sender, EventArgs e)

I Do not really understand whats the problem, because it´s working on my machine. Only thing would be that im using embedded resources in a wrong way.

Some has advice for me?

Hi,

How exactly are you using GemBox.Spreadsheet, from GAC (installed via Setup), from NuGet, or as a private assembly?

Nevertheless, perhaps the easiest way to resolve this would be to just remove the reference to GemBox.Spreadsheet and add it again.

Let me know if you need anything else.

Regards,
Mario

i installed the NuGet

reinstalling the NuGet was not a solution.

I had the GemSpreadsheet and the GemBundle installed.

Now i only have the GemBundle installed after deinstalling all of them, but it had no effect.

Regards

Hi,

Please send us a small Visual Studio project that reproduces your issue so that we can investigate it.

Regards,
Mario

Here is the programm, i shortened it a bit so only the unneccesary things are out now:
that is Form 4 of three

using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Drawing.Text;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using static System.Net.Mime.MediaTypeNames;
using static System.Net.WebRequestMethods;
using System.Reflection;
using System.Drawing;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using GemBox.Spreadsheet;
using Net.Pkcs11Interop.LowLevelAPI40.MechanismParams;

namespace Update_Report
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private static void Extract(string nameSpace, string outDirectory, string internalFilePath, string resourceName)
        {
            Assembly assembly = Assembly.GetCallingAssembly();

            using (Stream s = assembly.GetManifestResourceStream(nameSpace + "." + (internalFilePath == "" ? "" : internalFilePath + ".") + resourceName))
            using (BinaryReader r = new BinaryReader(s))
            using (FileStream fs = new FileStream(outDirectory + @"\" + resourceName, FileMode.OpenOrCreate))
            using (BinaryWriter w = new BinaryWriter(fs))
                w.Write(r.ReadBytes((int)s.Length));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            DialogResult result = MessageBox.Show("Are you sure you want to Save?\n\nAt the moment there is no possibility to load your saved file in again.\n\nIf you want to get to the next side click 'YES'.", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                if (textBox1.TextLength > 3 & textBox3.TextLength > 3 & textBox6.TextLength > 3 & textBox7.TextLength > 3 & textBox15.TextLength > 3 & comboBox1.Text.Length > 2 & comboBox2.Text.Length > 3 & comboBox3.Text.Length > 3 & comboBox4.Text.Length > 3)
                {
                    try
                    {

                        

                        string FirstPagePath = @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp first page.xlsx";
                        string FirstPagePathEdited = @"C:\ProgramData\UpdateReports\01_MainPage\Software Update Report - temp first page.xlsx";
                        string NewFirstPagePath = @"C:\ProgramData\UpdateReports\01_MainPage\Software Update Report - " + textBox1.Text + " - " + dateTimePicker1.Text + ".xlsx";

                        Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();


                        Workbook wb;
                        Worksheet ws;

                        wb = excel.Workbooks.Open(FirstPagePath);
                        ws = wb.Worksheets[1];


                        ws.Cells[5, 3] = textBox3.Text;                                 //Customer
                        ws.Cells[6, 3] = textBox1.Text;                                 //Evatec Asset
                        ws.Cells[7, 3] = textBox2.Text;                                 //Customer Asset
                        ws.Cells[8, 3] = comboBox2.Text;                                //Product Group
                        ws.Cells[9, 3] = comboBox1.Text;                                //Software

                        toolStripProgressBar1.Value = 10;

                        ws.Cells[11, 3] = textBox5.Text;                                //Initiate
                        ws.Cells[12, 3] = comboBox3.Text;                               //Tool State
                        ws.Cells[13, 3] = textBox6.Text;                                //Author

                        toolStripProgressBar1.Value = 20;

                        ws.Cells[15, 3] = DateTime.Now;                                 //Document Date
                        ws.Cells[16, 3] = comboBox4.Text;                               //Update Period
                        ws.Cells[17, 3] = comboBox5.Text;                               //Actual period
                        ws.Cells[4, 11] = comboBox6.Text;                               //Status

                        toolStripProgressBar1.Value = 30;
                        if (textBox19.TextLength > 8)
                        {
                            Microsoft.Office.Interop.Excel.Range excelCell = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("C20", "C20");
                            ws.Hyperlinks.Add(excelCell, textBox19.Text, Type.Missing, "Click to open", "Click to open");                             //SW File Link
                        }
                        if (textBox20.TextLength > 8)
                        {
                            Microsoft.Office.Interop.Excel.Range excelCell1 = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("C19", "C19");
                            ws.Hyperlinks.Add(excelCell1, textBox20.Text, Type.Missing, "Click to open", "Click to open");                             //Customer file Link
                        }
                        toolStripProgressBar1.Value = 40;

                        ws.Cells[24, 1] = richTextBox1.Text;                            //Reason Update
                        ws.Cells[30, 1] = richTextBox2.Text;                            //Additional Information
                        ws.Cells[10, 11] = richTextBox3.Text;                            //Reason for Status

                        toolStripProgressBar1.Value = 50;

                        ws.Cells[5, 8] = textBox7.Text;                                 //Software Revision
                        ws.Cells[6, 8] = textBox8.Text;                                 //Framework/EIB
                        ws.Cells[7, 8] = textBox9.Text;                                 //GUI/Peer Tool Orchestrator
                        ws.Cells[8, 8] = textBox10.Text;                                //PLC Version
                        ws.Cells[9, 8] = textBox11.Text;                                //PLC Safety Version
                        ws.Cells[11, 8] = textBox15.Text;                               //Software Revision
                        ws.Cells[12, 8] = textBox14.Text;                               //Framework/EIB
                        ws.Cells[13, 8] = textBox16.Text;                               //GUI/Peer Tool Orchestrator
                        ws.Cells[14, 8] = textBox13.Text;                               //PLC Version
                        ws.Cells[15, 8] = textBox12.Text;                               //PLC Safety Version


                        toolStripProgressBar1.Value = 60;

                        if (comboBox1.Text == "Xperience")
                        {
                            ws.Cells[6, 6] = "Framework:";                              //Labeling
                            ws.Cells[7, 6] = "GUI:";                                    //Labeling
                            ws.Cells[12, 6] = "Framework:";                             //Labeling
                            ws.Cells[13, 6] = "GUI:";                                   //Labeling
                        }
                        if (comboBox1.Text == "PTO Classic")
                        {
                            ws.Cells[6, 6] = "EIB:";                                    //Labeling
                            ws.Cells[7, 6] = "Peer Tool Orchestrator:";                 //Labeling
                            ws.Cells[12, 6] = "EIB:";                                   //Labeling
                            ws.Cells[13, 6] = "Peer Tool Orchestrator:";                //Labeling
                        }
                        if (comboBox1.Text == "Khan")
                        {
                            ws.Cells[6, 6] = "Khan Version:";                           //Labeling
                            ws.Cells[7, 6] = "EEC Version:";                            //Labeling
                            ws.Cells[8, 6] = "QCM Version:";                            //Labeling
                            ws.Cells[9, 6] = " ";                                       //Labeling
                            ws.Cells[12, 6] = "Khan Version:";                          //Labeling
                            ws.Cells[13, 6] = "EEC Version:";                           //Labeling
                            ws.Cells[14, 6] = "QCM Version:";                           //Labeling
                            ws.Cells[15, 6] = " ";                                      //Labeling
                        }
                        if (comboBox1.Text == "LLS")
                        {
                            ws.Cells[6, 6] = "GUI Version:";                            //Labeling
                            ws.Cells[7, 6] = "PLC Version:";                            //Labeling
                            ws.Cells[8, 6] = " ";                                       //Labeling
                            ws.Cells[9, 6] = " ";                                       //Labeling
                            ws.Cells[12, 6] = "GUI Version:";                           //Labeling
                            ws.Cells[13, 6] = "PLC Version:";                           //Labeling
                            ws.Cells[14, 6] = " ";                                      //Labeling
                            ws.Cells[15, 6] = " ";                                      //Labeling
                        }
                        toolStripProgressBar1.Value = 70;

                        wb.SaveAs(FirstPagePathEdited);
                        wb.Close();

                        toolStripProgressBar1.Value = 80;

                        System.IO.File.Move(FirstPagePathEdited, NewFirstPagePath);

                        toolStripProgressBar1.Value = 90;

                        Process[] workers = Process.GetProcessesByName("Excel");
                        foreach (Process worker in workers)
                        {
                            worker.Kill();
                            worker.WaitForExit();
                            worker.Dispose();
                        }

                        toolStripProgressBar1.Value = 100;
                        toolStripStatusLabel1.ForeColor = System.Drawing.Color.Green;
                        toolStripStatusLabel1.Text = "Saved";

                        MessageBox.Show("Data successfully saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                        MessageBox.Show("System Error Message:\n\n" + ex.Message + "\n \nMaybe the folder directorys are not wherethey are supposed to be, control the folder directorys and naming of folders.", "Error Message XX", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        toolStripStatusLabel1.ForeColor = System.Drawing.Color.Red;
                        toolStripStatusLabel1.Text = "Error X";
                        toolStripProgressBar1.Visible = false;

                        return;

                    }
                }
                else
                {
                    DialogResult result1 = MessageBox.Show("Make sure all neccessary entries are made.\n\nThe fields required are marked with a star '*'.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (result1 == DialogResult.OK)
                    {
                        return;
                    }
                }




                var Form2 = new Form2();
                Form2.Show();
                this.Hide();
            }
            else if (result == DialogResult.Cancel)
            {
                return;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {

                string dir = @"C:\ProgramData\UpdateReports\01_MainPage";
                string dir1 = @"C:\ProgramData\UpdateReports\02_Comments";
                string dir2 = @"C:\ProgramData\UpdateReports\03_TestResults";
                string dir3 = @"C:\ProgramData\UpdateReports\04_Propositons";
                string dir4 = @"C:\ProgramData\UpdateReports\05_FinalReport";
                string dir5 = @"C:\ProgramData\UpdateReports\06_Templates";
                string dir6 = @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp first page.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Comment.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Test Result.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Proposition.xlsx";
                string dir7 = @"C:\ProgramData\UpdateReports\07_Single PDFs";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (!Directory.Exists(dir1))
                {
                    Directory.CreateDirectory(dir1);
                }
                if (!Directory.Exists(dir2))
                {
                    Directory.CreateDirectory(dir2);
                }
                if (!Directory.Exists(dir3))
                {
                    Directory.CreateDirectory(dir3);
                }
                if (!Directory.Exists(dir4))
                {
                    Directory.CreateDirectory(dir4);
                }
                if (!Directory.Exists(dir5))
                {
                    Directory.CreateDirectory(dir5);
                }

                if (!System.IO.File.Exists(dir6))
                {

                    Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp first page.xlsx");
                    Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Comment.xlsx");
                    Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Test Result.xlsx");
                    Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Proposition.xlsx");
                }
                if (!Directory.Exists(dir7))
                {
                    Directory.CreateDirectory(dir7);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("System Error Message:\n\n" + ex.Message + "\n \n Maybe the folder directorys are not wher ethey are supposed to be, control the folder directorys and naming of folders.", "Error Message XX", MessageBoxButtons.OK, MessageBoxIcon.Error);

                toolStripStatusLabel1.ForeColor = System.Drawing.Color.Red;
                toolStripStatusLabel1.Text = "Error X";
                toolStripProgressBar1.Visible = false;

                return;
            }
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                Process.Start(textBox20.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check your added link it might not work.\n\n" + ex.Message, "Error XX", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                Process.Start(textBox19.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check your added link it might not work.\n\n" + ex.Message, "Error XX",MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to skip to the next Page?\n\n All entries made will be deleted.", "Notification", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (result == DialogResult.OK)
            {
                var Form2 = new Form2();
                Form2.Show();
                this.Hide();
            }
            else if (result == DialogResult.Cancel)
            {
                return;
            }
        }

        private void comboBox6_TextChanged(object sender, EventArgs e)
        {
            if(comboBox6.Text == "Rollback")
            {
                groupBox6.Visible = true;
            }
            else if (comboBox6.Text == "Canceled")
            {
                groupBox6.Visible = true;
            }
            else
            {
                groupBox6.Visible = false;
            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox2_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox20_TextChanged(object sender, EventArgs e)
        {
              
        }

        private void textBox19_TextChanged(object sender, EventArgs e)
        {
               
        }
        public static string SetValueForText1 = "";
        public static string SetValueForText2 = "";

        private void toolStripMenuItem10_Click(object sender, EventArgs e)
        {
            String openPDFFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\SW Update Report Instructions.pdf";//PDF DOc name
            System.IO.File.WriteAllBytes(openPDFFile, global::Update_Report.Properties.Resources.SW_Update_Report_Instructions);//the resource automatically creates            
            System.Diagnostics.Process.Start(openPDFFile);
        }

        private void toolStripMenuItem8_Click(object sender, EventArgs e)
        {
            var Form3 = new Form3();
            Form3.Show();
        }
    }
}

I don’t believe that your problem is with the code, it is with the project file (“.csproj”).
I need to investigate your GemBox.Spreadsheet reference.

Hi,

Try uninstalling GemBox.Bundle NuGet package and then install it again.
After that rebuild your project.
Does this solve your issue?

Regards,
Mario

sadly it does not, i already tried this.

Strange thing is, that it works on my machine but on a diffrent one it shows this error on loading the Form.

Please send us a complete project so that I can try to reproduce it on my end.

I’m afraid I was unable to reproduce your issue.
Inside the “Update Report - Kopie\bin\Debug” folder I can see there is a GemBox.Spreadsheet.dll file.

Just in case, can you check that you don’t have GemBox.Spreadsheet installed on that other machine?

Also, can you try creating some small sample project, that has GemBox.Bundle package and creates a simple “HelloWorld.xlsx” file. Then try running that project on that problematic machine.
Let me know if the problem occurs on it again.

Hi,
for sure it´s not installed on the other machine.

I´ll check what you have mentioned

okay i found the issue.

i copyed only the.exe file onto the other machine. I then tried to copy the.exe file somewhere else on my machine and it also didn´t worked. It showed the same error.

I the copied the GemBox.Spreadsheet.dll file in the same folder where the .exe file is and startet the application again. - no issue.

So my question is: how can i now implement this.dll into the .exe file? so i don´t need to always copy the.dll

Thanks for your help :slight_smile:

Hi Andreas,

Try this:

  • Uninstall GemBox.Bundle package.

  • Download GemBox.Spreadsheet.dll from the bugfixes page (version 49.0.35.1274): GemBox.Spreadsheet Bug Fixes

  • Add the GemBox.Spreadsheet.dll to some folder inside your project and mark it as Embedded Resource (from Visual Studio select the GemBox.Spreadsheet.dll file, go to the properties window, and set “Build Action” to “Embedded Resource”).

  • Add a reference to that GemBox.Spreadsheet.dll file (from Visual Studio right-click your project and then Add → Reference → Browse).

  • As a result, you should have something like this inside your CSPROJ file:

  <ItemGroup>
    <Reference Include="GemBox.Spreadsheet">
      <HintPath>MyFolder\GemBox.Spreadsheet.dll</HintPath>
    </Reference>
  </ItemGroup>

...

  <ItemGroup>
    <EmbeddedResource Include="MyFolder\GemBox.Spreadsheet.dll" />
  </ItemGroup>
  • After that, handle the AddDomain.AssemblyResolve event, for example like this:
namespace MyApplication
{
    public partial class Form1 : Form
    {
        static Form1()
        {
            // Used for debugging (finding out) embedded resource names.
            //var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();

            AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
        }

        private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs e)
        {
            if (e.Name != null && e.Name.Contains("GemBox.Spreadsheet"))
            {
                // IMPORTANT: change the "resourceLocation" to match the GemBox.Spreadsheet.dll location in your application.
                // To see what is the correct value, uncomment the above commented line of code
                // and find the GemBox.Spreadsheet.dll item in "resourceNames" array.
                string resourceLocation = "MyApplication.MyFolder.GemBox.Spreadsheet.dll";

                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceLocation))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return Assembly.Load(data);
                }
            }

            return null;
        }

        public Form1()
        {
            // Put your license key here.
            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            InitializeComponent();
        }

        // ...
    }
}

I hope this helps.

Regards,
Mario

1 Like