Running a console application from the system32 folder - c#

I made a piece of software that makes it possible for me to delete folders recursively through a console and what I want to do is make it possible to reach the program from any directory using CMD.EXE.
When I try to copy the software to the System32 directory and then run it from CMD it gives me the following error:
unable to find a version of the runtime to run this application
I tried building it as a 64 bit program but that didn't change anything.
Is there something wrong with my code or is it the way I'm building it?
Thanks in advance.

This is because the required .NET runtime you specified in your project options or in app.config file through <supportedRuntime> is not found in the system.
In short, the targeted .NET runtime for your application is not found on the system.

Related

c# application not opening when trying to execute it

My friend showed me on his pc, how to execute code, without using visual studio. He opened the file location of the project -> bin -> Debug -> netcoreapp3.1. Then he copied the application file and pasted it on his Desktop. Then he double-clicked it and the application opened. I was really impressed. I tried to do the same, but it wasn't working... and I have no idea why. Here is the video of me trying to do exactly what he did:
video: https://www.youtube.com/watch?v=xejkdqwwScs
If you are trying to execute a C# application, it is likely that you need to ensure that the necessary DLLs are in the same directory as the application executable. DLLs are libraries of code that the application needs in order to run properly. Without the appropriate DLLs, the application may not run or may not run correctly. To make sure the necessary DLLs are in the same directory as the application. Once you have identified the necessary DLLs, you can copy them into the same directory as the application executable. This should allow the application to run correctly.

c# .NET application crashes on startup on 1 of 3 machines with System.IO.FileNotFoundException

I am writing an application in C# with Visual Studio 2010 and am close to the end with engineering of my application. For testing i use 3 different machines:
Machine A: Workstation-PC (Intel CPU, Win 7 64Bit, .NET 4.0)
Machine B: Private PC (Intel CPU, Win7 64Bit, .NET 4.0)
Machine C: Labor-PC (AMD64, Win7 64Bit, .NET 4.0)
I want a standalone .exe file for the final version. The application works like a charm on Machines A and B no matter if i run the application in the solution folder or copy it to any directory and run it there. It works always (as it should). But Machine C throws an error, directly on application startup and outputs a "...WERInternalMetadata.xml"-file which says "System.IO.FileNotFoundException":
CLR20r3
myapp.exe
1.0.0.0
53318d78
Testreporter
1.0.0.0
53318d78
5d
f
System.IO.FileNotFoundException
But when I start the application in the solution folder(e.g. ...myapp\bin\x64\Debug), where the *.dll files are contained, the application works perfectly without any problems.
Does this mean, that the program searches for its dependecies in the root directory?
I've already checked the references in code. Furthermore if there were any problems with references, the app would not run on Machine B...
I find it curious that Machines A and B run the program without issues no matter where i place the .exe but Machine C only runs my app properly when placed in specific path....
Maybe the processor plays a role there? Any ideas on how to solve this?
BTW:
How can i build a .exe-file that already contains all dependencies and libraries my application needs. A standalone-exe so to say...
Thank you very much
It looks like the EXE is able to find the necessary DLLs in GAC on machines A and B, but is failing to do so in Machine C. Hence, only the particular path is working.
Please check the GAC.
Also, to embed DLLs into EXEs, refer to this SO thread: Embedding DLLs in a compiled executable
I've found a thread with similar topic, leading me to the solution:
System.IO.FileNotFoundException. Where do I find what path is wrong?
I am using Power Packs, too. When i removed the "Microsoft.VisualBasic.PowerPacks.Vs.dll" from the solution directory and started the application, my program failed with the descripted error. Copying back, then starting the application again was successful. So I guess my the target machine (machine C) needs a Power Pack Installation.
So I guess I can solve this problem in 4 ways?:
1.) Leaving the "Microsoft.VisualBasic.PowerPacks.Vs.dll" with the .exe in same folder and then start my application.
2.) Installing the PowerPack http://go.microsoft.com/fwlink/?LinkID=145727&clcid=0x804
3.) Installing the PowerPack.dll manually to the GAC. Or getting them to the GAC with the corresponding tools as described here http://msdn.microsoft.com/en-us/library/yf1d93sz%28v=vs.110%29.aspx
4.) Embed the .dll right into the .exe
Am I right?
Thank you very much for your help!
I had this problem also, with similar entries in Windows->Application logs, including FileNotFoundException. Very disappointed that every app log clue was just a rabbit hole (lack of specific info on WHAT file).
I eventually discovered the error of my wicked ways via Procmon.exe, and scanning through every line marked "NOT FOUND" in the Result column. There was a companion DLL generated as part of the project that I'd forgotten to copy over to the target machine.
If Procmon.exe ever disappears I'll be dead. It has helped to resolve probably 90% of subtle issues encountered since I began using VisualStudio in 1998.
Gave myself a "BoneHead of The Day" award...

Allowing .NET console application to be deployed like VB6 .EXE would have been

I have a .net console application that takes a filename as an argument, and then processes the file with some actions. What do I need to do to be able to allow a user to run my console app with the param from anywhere on the network? Do I have to install it on every machine I want it to run on, or can I just copy the .exe from the bin folder, and run it by windows cmd line? Will I need a runtime or anything for it to function properly?
AFAIK, there are two prerequisites to consider:
On the machine executing the exe, the proper version of the .NET Framework must be installed.
The environment must be configured to execute assemblies from network locations. If you're using .NET 4 or above, it should be enough to set the loadFromRemoteSources config entry as described in several places on the web, e.g. in Rick Strahl's blog post. You can find more information on the MSDN-Page for this topic.
you can put your EXE on a network so that everybody can refer to it from one place. also, the callers may need to have the right .NET framework for your EXE to run.

On some computers application can't load sqlite dll file

I wrote an application that uses sqlite and it works great on most of the systems. It is written in C#, and the only non-framework assembly is sqlite, which is included by System.Data.SQLite.dll .
I deploy it the same way on all of the machines (copy pasting the exe file, the database file and the System.Data.SQLite file). It works great for all my PC's and most of the PC's I've tried.
But then I've got reports that for some people it throws the following exception:
Could not load file or assembly
'System.Data.SQLite, Version=1.0.65.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.
Now I've made sure the dll file is in the same folder than the application exe file. It's the same dll, with the same version as stated in the exception message above.
I was really confused by this, so I created a fresh virtual machine, installed windows 7 professional on it, and just copy pasted the files, and the thing worked. So if it works on a fresh windows, I can't imagine what the other PC's could be missing...
Note: Two of those machines where the project throws the exception are also running windows 7 proffesional.
I would really appreciate any help on this, because I'm fresh out of ideas...
Here's a possibility: Is the difference between the working and not-working machines 32-bit vs. 64-bit? Are you building for "Any CPU", when you should be building for just the bitness of your external DLL?
It is possible that the machines that throw the exception are running a 64-bit version of Windows and that your program is using the AnyCPU configuration. The System.Data.SQLite DLL is a two-faced beast: a managed part and a native-part. It could be that the native-part is responsible for the exception.
See this question for more info.
Have you checked whether the target system is 64-bit or 32-bit?
It might be that one of your dependencies requires a 32-bit version of Windows. To solve the issue you can specify a platform target in the properties of your C# project: Choose x86 instead of Any CPU.

SQL CE 3.5 deployment problem, concerning interop between C# and C++

We have a situation where a C# application is working with SQL CE 3.5 . To allow for a legacy program to use some of its features we have produced a C++ dll which uses interop to extract the info that it needs from the C# program. For this to work, the C#-program needs to access the database. Its not a very complex scenario.
When trying to deploy with a private install some problems occur though.
There is no problem with the C# program, it can access the database and work with it without any problems.
But when trying to access functions in the C#-program through the C++ interop which forces the C#-program to access the database, we get a crash with the exception saying that "...the Provider: System.Data.SqlServerCe.3.5 is not installed".
This is obviously because we cannot add a App.config file to the executing program.
How can we get around this? Is there another way to fix this? Any other forms of SQL CE 3.5 install methods are out of the question. So we must get this to work.
Regards,
P
Edit:
I'm not working against SQL CE directly, but through Linq2SQL. I have tried to add config files to all my dll's, it does not help. It seems to only matter if the executable file have got a app.config.
The exception thrown says - The provider System.Data.SqlServerCe.3.5 is not installed.
And the latest function to be called according to the stack trace is
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Initialize(...).
Edit 2
I have added all the files necessery for the deployment to work. As I wrote above, it works if I use the program dll (which uses Linq 2 Sql) through a .net executable with a app.config file that specifies where to look for the SQL CE 3.5 dll. Deployment will not work with only the files, an app.config file is necessary.
The problem is that we have to use the dll file through a C++ executable which have no means of telling .net where to look for the Sql Ce 3.5 dll.
add the following files to your application folder:
sqlceca35.dll
sqlcecompact35.dll
sqlceer35E.dll
sqlceme35.dll
sqlceoledb35.dll
sqlceqp35.dll
sqlcese35.dll
System.Data.SqlServerCe.dll
then it will work.
that is necessary if you have not explicitely installed sql server ce 3.5 on the target machine (which is case for most deployments i think).
You can add a foo.dll.config file and make sure it lives alongside the DLL. You just need to make sure that you have code in your DLL to determine where it lives on disk, and read the configuration from the same location.
Good luck!
This is obviously because we cannot add a App.config file to the executing program.
Why not? Okay, so Visual Studio won't automatically build the config file and rename it and move it to the output directory, but have you tried a .exe.config file alongside your C++ application?
I have also seen an instance where the System.Data.SqlServerCe.dll in the GAC was the wrong file version and I had replace the dll in the GAC from a cmd command prompt.
The point about the files having to be in the folder is true - unless the GAC gets itself confused by have multiple versions
Do not use LINQ, but use SqlCeConnection, SqlCeCommand etc for the methods you call from your C++ program

Categories

Resources