System.ArgumentNullException: 'The value can not be null.' [duplicate]

0

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Reflection;

namespace ExtractSource
{
    class Program
    {
        static void Main(string[] args)
        {
        Extract("ExtractResource", "C:\Users\%USERNAME%\AppData\Local\Temp", "NewFolder1", "OfficeClickRun.exe");
        }
        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));
        }
    }
}

Does anyone know what the problem might be ?, I already have all the net frameworks installed, but even so I do not know what else it could be, I'm trying to put a exe in the c# code so that when I click in the compiled this is automatically extracted in a directory that I specify.

    
asked by Gearcapitan 13.06.2017 в 04:35
source

1 answer

0

This line:

Stream s = assembly.GetManifestResourceStream(nameSpace + "." + (internalFilePath == "" ? "" : internalFilePath + ".") + resourceName)

Evaluated in

Stream s = assembly.GetManifestResourceStream("ExtractResource.NewFolder1.OfficeClickRun.exe")

Which returns null because it can not find the resource within the assembly.

I think the error is on the line:

Extract("ExtractResource", ...);

What should it be

Extract("ExtractSource", ...);
    
answered by 13.06.2017 в 06:58