I have a project which is the core of our application. We build several DLLs and an EXE.
We then have custom projects which use pre-built core DLLs and EXE and add customisations/extra bits as required. These customisations are always DLLs, the core EXE is always used. The core DLLs/EXE are referenced by the custom solution.
I'm having a bit of a problem while debugging getting the custom DLLs to load. Because the EXE is pre-built we use one the projects as the startup project which points to the location of the EXE and the rest of the DLLs. However it then doesn't seem to the load the startup project DLLs.
How should I be setting my custom solution/projects up when the EXE is already built?
(NOTE: the custom DLLs provide components which are loaded reflectively from metadata if you're wondering)
UPDATE: Current approach is to have a post-build event in the "top-level" project of the custom solution which copies all the core DLLs and EXE into the bin/Debug directory. Then set that top level project as the startup project and point to the copied EXE in bin/Debug. It then finds the DLL because it is in the same directory as the EXE (along with all the others).
Selecting a DLL as the startup project does not in any way guarantee that it actually gets loaded. That EXE you are using has to use Assembly.Load/From() to get the DLL loaded. At that point does the debugger step in and activate the break-points you set.
Easy to tell from the Debug + Windows + Modules window. If you don't see your DLL loaded in that window then nothing is going to happen. You'll need to find out what the exact configuration rules are for that EXE so that it will load the DLL you want to debug.
You can run the .exe, then attach Visual Studio Debugger to the process. Make sure the .pdb for your .dll is in the executing directory.
Related
I have 3-layer MVVM project, my solution folder, DLL folder and BLL folder are inside 'source > repos >' and project loads normally
But if I move BLL or DLL(or both) to some other folder, or Desktop for example, my project doesn't load correctly and file moved to Desktop defined as not founded in solution explorer
How could I fix it? I need put all this three project folders(DLL, BLL, View) to one folder, because I need to share it as one big project, but I can't, because any movement with files or folder finishes with error 'Files not founded'
Sadly can not send images here, in y question(
Thanks in advance for your answers!
Check for that in your project: is it in the references list? If it is, check that it's built for the same CPU type as your project, and that the Reference properties option "Copy Local" is set to true.
If it isn't, try adding it. If that works, try rebuilding. If it doesn't, then it's probably a Native Library, and you need to ensure that the DLL is either in the EXE folder, or in a folder on the current PATH that Windows uses to locate executables.
You Need to compile the DLL project into a dll file and then refer to the compiled dll file.
Or just use project references to add your DLL project and BLL project.
I am trying to build a project in C# which uses some unmanaged dll files (MSVCRT.DLL, DFORRT.DLL, ...). There is no direct reference to the MSVCRT.DLL file in the project(this file is referenced by another dll and not directly by my program)
I want this dlls to be copied to bin directory. if i set build action to Content i get this error on run time:
The procedure entry point _wcstoui64 could not be located in dynamic link library msvcrt.dll.
Which is weird. I cant use other build actions because i want my dlls to be published too(Build action=None wont cause any error but doesn't let me to publish my dlls)
If i completely remove all references to all the dlls and treat them like data files, or pictures(files that are not used in code but should be copied to the output) again i get the same error.
What is causing the problem? how can i publish my dlls?
I made a WPF program which uses SQLite. And by using Visual Studio 2012, it generates both Debug and Release version exe file. When I go to Debug or Release directory and run my exe file, e.g. MultiStart.exe, it can run normally.
But if I copy the MultiStart.exe to my Desktop and try to run it, it failed.
By several tests, I found that I also need to copy files MultiStart.exe.config and System.Data.SQLite.dll to my Desktop. And then it can run now.
But why? Do we have better solution so that I can make it run without addition files?
Thanks!
Why my WPF program cannot run without Visual Studio?
The question title is not really accurate since it's not really related Visual Studio. MultiStart.exe is dependent on configuration (MultiStart.exe.config) as well as other assemblies (System.Data.SQLite.dll). Without these dependencies the application cannot run (because that is how .NET works).
WPF doesn't necessarily need a config file to run so the question is what is in your config file that the application needs. It might be possible to move this configuration information into the code (e.g. connection string) and remove the app.config but then the values will be hard coded in the application.
In terms of dependent assemblies, instead of deploying them it is possible to embed them as resources and then use the AppDomain.AssemblyResolve Event to read the assembly from a resource (see Embedding assemblies inside another assembly for an example).
Another approach instead of embedding assemblies as resources is to merge them into one assembly. ILMerge is a popular choice for merging assemblies but I read that it can have issues with WPF assemblies (not sure if that applies to you). See Merging dlls into a single .exe with wpf for some other ideas for merging assemblies with WPF.
Note that setting PATH variables does not work because .NET does not use the PATH for resolving assemblies -- see How the Runtime Locates Assemblies for the details.
Another, option instead of copying the MultiStart.exe to the desktop is to use a shortcut on the desktop that links to the appropriate directory. Perhaps that is a simpler solution
You can also use ILMerge to merge all dependencies into single .exe file to simplify distributiuon of your application.
More detaiils on ILMerge can be found here: ILMerge on CodeProject
Example of usage: ilmerge /target:winexe /out:YourDestinationApp.exe
YourCurrentProgram.exe System.Data.SQLite.dll
Better solution that i used to do with my windows form apps is, Copy the entire folder, which contains supporting files. place it where you want. then create a shortcut of your .exe on your desktop. That always worked for me.
Because you are missing some dependency. You can open your config file and set the dependency...but I wouldn't recommend you to change config file manually.
You can also copy the dependent dll in system32 folder. ..but its only a trick because exe first search dlls in current folder than system 32 folder.
Because you're missing things from your PATH. Visual Studio is probably set to copy DLLs to the target directory on build.
You're almost certainly pulling in external libraries. Some of these are part of .NET, while others are packaged in libraries in specific folders. When you start your exe, it looks in your PATH and the current folder for everything (which includes all DLLs Visual Studio copied).
When you moved the exe to the desktop, suddenly it had no idea where those DLLs are. You haven't specifically added them to your PATH, and they are no longer in the current folder. This is why copying those DLLs to your desktop magically made them work.
Unless you stop use SQLite, there is not a way for you to not need that DLL (there are lots of ways to package/reference it though).
I have created a project in C#.NET, which 3 config files and 2 dlls. For creating setup, I am using Visual Studio Installer(Setup Project). I would like to organize my primary output as follows:
Separate folder for config files and dlls. I tried below in the image but after installing the application is not running.
The dlls you referenced and the default configs for your assembly must be in the same folder as the executable. You cannot just put them where you want them.
If you load those dll assemblies yourself and load those configs yourself in your assembly, you are free to put them where you want. But that's probably not worth the amount of time you'd have to put into it.
I'm building a loosely-coupled app, where the main exe project only contains references to an assembly with interfaces. The concrete implementations of those interfaces are in assemblies that are referenced indirectly - via IoC. However, those assemblies' build output doesn't get copied to the bin\Debug folder of the exe, which means my IoC can't find them.
How do I make sure those assemblies are copied, if there is no actual project/assembly reference?
You can create a post-build event to copy the desired files to the output directory after the project is built.
did you try to right click your exe project -> Project Dependencies.
Then tick all the projects that you need to be copied over your bin\Debug folder ?
Alternatively what Konamiman said would work as well.
You can make sure they are built before the main exe project by checking the relevant projects in Build Dependencies dialog (found in the Project context menu).
However I think you need to use xcopy in a post-build step to actually copy the assemblies.