C#C
C#3y ago
12 replies
The Joker

✅ System.NullReferenceException: 'Object reference not set to an instance of an object.' C#

hello I'm facing an error I wanted to see if someone can help me this happens only when I try to extract the texture folder, in the others it works fine.

private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataHierarchy == null)
            {
                return;
            }
            TreeNode selectedNode = packTreeView.SelectedNode;
            if (selectedNode == null)
            {
                return;
            }
            AskDestinationForm askDestinationForm = new AskDestinationForm();
            DialogResult dialogResult = askDestinationForm.ShowDialog();

            

            if (dialogResult == DialogResult.OK)
            {
                string destinationPath = askDestinationForm.DestinationPath;
                string fullPath = selectedNode.FullPath;
                fullPath = Pack.Util.Path.FormatPath(fullPath);
                FileWriter fileWriter = new FileWriter();
                
                if (selectedNode.Tag is Pack.Structure.File)
                {
                    dataHierarchy.ExtractFileTo(destinationPath, fullPath, fileWriter);
                }
                else
                {
                    dataHierarchy.ExtractFolderTo(destinationPath, fullPath, fileWriter);
                }
            }
        }
Was this page helpful?