Question Opening a Resource File?

Roast247

New member
Joined
Jun 15, 2024
Messages
3
Programming Experience
Beginner
Hello, I am getting the following error

error:
Argument 1: cannot convert from 'byte[]' to 'string[]'

and the code causing that error is

code:
Process.Start(Properties.Resources.telephone);

Any and all help to resolve this issue will be much appreciated
 
What EXACTLY did you do to add that resource in the first place? What EXACTLY are you expecting that code to do? Please provide a FULL and CLEAR explanation of the problem. We only know what you tell us so you have to tell us EVERYTHING that's relevant.
 
What EXACTLY did you do to add that resource in the first place? What EXACTLY are you expecting that code to do? Please provide a FULL and CLEAR explanation of the problem. We only know what you tell us so you have to tell us EVERYTHING that's relevant.

I uploaded it to the Resources of the project? I'm expecting to run the file, which is an executable. Not sure how I would be able to be any more clearer than that.
 
Not sure how I would be able to be any more clearer than that.

Pretty easily, to be honest, but it will do because the issue is clear from what you provided. It may not have been though. Honestly, you're far from the only one but a lot of people are terrible at explaining things that they even did with their very own hands. You can say "I opened X page, I clicked Y button, I selected Z file", etc. Details often matter. You should ALWAYS provide a FULL and CLEAR explanation of the problem up front.

Anyway, when you add a file to your project resources, a property is generated through which you access the data. The type of that property depends on the type of file you added. It might be string for a text file or Image for a picture file and it will be byte[] for a binary file like an executable. You could have easily seen the type of that property, i.e. Properties.Resources.telephone, by simply mousing over it in the code window. Intellisense would have told you as you typed it too, I think. If you did any research on the Process.Start method, nothing you found would have suggested that you could pass a byte array to it as an argument. It expects a string containing the path of a file, so you need a file in the first place. You have a resource, which is data compiled directly into your application. Very much not the same thing.

If you want to be able to run this EXE file then you need a file, so you'll need to extract the data from the resource and save it as a file first, then pass the path of that file to Process.Start. Be aware though, that many antivirus software packages will consider that suspicious activity and block it. If you want your app to run another EXE, the safest option is to deploy that EXE with your own and put them in the same folder to start with.
 
Pretty easily, to be honest, but it will do because the issue is clear from what you provided. It may not have been though. Honestly, you're far from the only one but a lot of people are terrible at explaining things that they even did with their very own hands. You can say "I opened X page, I clicked Y button, I selected Z file", etc. Details often matter. You should ALWAYS provide a FULL and CLEAR explanation of the problem up front.

Anyway, when you add a file to your project resources, a property is generated through which you access the data. The type of that property depends on the type of file you added. It might be string for a text file or Image for a picture file and it will be byte[] for a binary file like an executable. You could have easily seen the type of that property, i.e. Properties.Resources.telephone, by simply mousing over it in the code window. Intellisense would have told you as you typed it too, I think. If you did any research on the Process.Start method, nothing you found would have suggested that you could pass a byte array to it as an argument. It expects a string containing the path of a file, so you need a file in the first place. You have a resource, which is data compiled directly into your application. Very much not the same thing.

If you want to be able to run this EXE file then you need a file, so you'll need to extract the data from the resource and save it as a file first, then pass the path of that file to Process.Start. Be aware though, that many antivirus software packages will consider that suspicious activity and block it. If you want your app to run another EXE, the safest option is to deploy that EXE with your own and put them in the same folder to start with.

Alright, I've been trying to find any resource on how to extract the data from the resource and save it as a file, and can't find anything. I also can't find anything on how to deploy the exe alongside the main EXE. can you please guide me? Thanks
 
Alright, I've been trying to find any resource on how to extract the data from the resource and save it as a file, and can't find anything.
That's because you're looking for the wrong thing. You're already extracting the data. Properties.Resources.telephone IS the data. I already told you that in my previous post. All you need to do is save that byte array to a file. I just did a web search for "c# save byte array to file" and, as expected, the very first result provided an example of using the File.WriteAllBytes method.
I also can't find anything on how to deploy the exe alongside the main EXE. can you please guide me? Thanks
That would depend how you're deploying your application in the first place. If you're simply copying your EXE to another machine then you simply copy both EXEs to the other machine, exactly as you'd expect. If you're creating an installer then we'd need to know exactly how you're doing that in order to know how you would need to modify it to include another file. Of course, you could actually start by looking for yourself at what the installer creation tool provides in the way of functionality to include files. It's likely not hidden.
 

Latest posts

Back
Top Bottom