System.DllNotFoundException in client's PC while click Once deployment - c#

I have created an application in C# and WPF. The application uses a DLL written in C++ language.
I have imported this DLL in my C# application using DLLImport function like
[DllImport("Project2013.dll")]
static extern void InitTasksDispatcher();
I have referenced the DLL by right clicking project-->Add-->Add Existing Item--> and gave the path of DLL and used it "Add as a link" option.
I have already ensured to set Build Action as "Content" and Copy to output directory parameter as "Copy Always".
Then I Change the mode to Release mode and build the whole solution. It succeeded.
Then I made setup using ClickOnce deployment and created the setup file.
Found that it is running well on a system having the visual studio professional 2013 but it failed on client system. It says System.DllNotFoundException and nothing else. I have made installed VC++ redistributable on client PC. Still, it causes problem.
I also copied the dll.deploy file on different locations like in Application Files folder and with setup file also. Still it does not work. Please help me out if anyone have faced the same before.

Have you tried specifically including it as part of the ClickOnce package? Go to Project properties -> Publish -> Application Files, locate the dll, and change the publish status to Include (not auto)

Related

My Visual Studio 2019 WPF app is setting a dll as the output when it should be an exe

This is my first time trying to make a deployable program. After creating a nice little WPF XAML app that runs (i.e. I can run the executable in the bin folder), I am trying to wrap it in a setup program.
After following multiple directions online for both WiX and "Microsoft Visual Studio Installer Projects". Both make installer packages, but they are only targeting the dll file from the WPF XAML output when I as for the "Primary Output". It seems this is stemming from the build of the WPF project.
How do I adjust the primary output of the build process so it is included in the setup program?
Screenshot of build output specifying the dll as the output file:
To add more details:
This could be one wpf(.net core) application instead of one wpf(.net framework). See the Output window in Elton's screenshot we can find the output is xx.dll instead of xx.exe.
If we create a Installer project in this solution, right-click the Installer project=>Add=>Project Output=>Primary output to contain the WPF's output in installer project, only the xx.dll is considered as wpf's output, but not xx.exe.
So after building the Installer project in VS, double-click the setup.exe(installer project's output), the wpf.exe is not well installed.
On top of Lance answer. You can add the publish items to your outputs near your main Primary Output.
1- Right-click on project and select Add => Project Output.
2- Choose your target project and select Publish Items from the list with your configuration.
3- Now you have another Output in your Application Folder.
Done. with every Batch Build you have your publish directory copied to application folder.
My Visual Studio 2019 WPF app is setting a dll as the output when it
should be an exe.
I'm sure you're using a WPF(.net core) project cause yesterday I happened to reproduce same situation in my machine. As for the cause of the issue, if you're interested in it, you may get some help from this issue. For .net core 2.2 and earlier, if we build a console(.net core) project, we'll get a xx.dll as output by default(Use dotnet xx.dll to run that).
But for .net core 3.0, I found this situation changes. Now if we build a Console(.net core) or WPF(.net core), apart from the xx.dll, we'll also get an xx.exe now. And I checked the Updated date of Installer Project and the Release date of WPF(.net core), the latest update of the Installer project is much earlier than the release of WPF(.net core), I guess maybe this is the cause? I'm not certainly sure how Installer Project recognize the output of one WPF project, but I suggest you can post this issue in DC forum , if it gets enough votes, the team will consider a fix.
Here're my workarounds which may help:
1.Use Add=>File instead of Add=>Primary Output:
Build the WPF project in release mode, navigate to the output path and copy that path. Then right-click Installer project=>Add=>Files to enter that path. Choose all files in output folder and click open:
Right-click the assembly file and choose Find in Editor:
Right-click the xx.exe=>Create a shortcut. Then move the shortcut to User's Desktop folder and set the AlwaysCreate property to be true.
After that, build the installer project and install that xx.msi or setup.exe in my machine, I'll get a shortcut in desktop, double-click it will run the wpf(core) application.
2.See this blog, we can use command like dotnet publish -r xxx -p:PublishSingleFile=true to get a single-file executable which is self-extracting and contains all dependencies (including native) that are required to run your app. In this situation, you don't need a Installer project to deploy your project. The single executable is enough. Hint from Lex Li in this issue.
Hope it helps :-)

Could not load file or assembly on installing the winform application

I have designed a winform application and with the help of Visual Studio 2010 i made a setup of the application.In the application i have used three external .dlls i.e Mysql, Itextsharp and Epplus.Every thing is fine while working in visual studio but as soon as i installed the setup and tried to access the application from there i got a very strange error i.e Could not load file or assembly for the other two dlls i.e Itextsharp and Epplus while there is no error for mysql.Also i did a cross check of the installation folder and i can see all the dlls used in my application to be available there ..
Actually i cross checked from the visual studio Command prompt and got to know that the application is trying to search these dlls at wrong place ..Why the application is searching it at wrong place ? How come it is getting Mysql.dll at the right folder and place and why it is searching other two at wrong place and folder..?
Please help me to find out ..what can be the possible reason for this strange error and what can be the solution..
Thanks..
Update
LOG: Appbase = file:///C:/Users/Vikas/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/ECV/
LOG: Using application configuration file: C:\Users\Vikas\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ECV\ECVNEW.exe.Config
Maybe the instalation is not copying all references. have you checked in the top references (the winform project) if you set the copy local =true for all the references you need, or even you can install them into the GAC.
for each dll that you are getting the errors change Copy Local property to true.
If you don't do this operation when you build project these dll aren't copied to the bin folder and if the PC where you use the program doesn't have these dll the program will fail
update
check if your project is targetting .net 4.5, maybe the dlls are targetting .net 4.0
update 2
go to solution explorer --> Properties --> build tab
set platform target to 'Any CPU' to ensures that your application will work on both 32 and 64bit computers.

Deployment of Visual Studio solution containing dll project and exe project

I have a Visual Studio 2010 solution that contains 3 projects: a dll project, an executable project, and the Installer project.
I am working on the dll and the executable concurrently. The executable is simply a front end for the library. While developing the two in Visual Studio I simply added a reference to the dll project from within the executable and it works fine.
What I'm having trouble with is the deployment. Ideally the dll would be compiled and installed in a subdirectory of the executable. Using the "Visual Studio Installer - Setup Wizard" project template for my installer doesn't seem to be giving me the options I need.
Am I going about this wrong by developing my backend and frontend in different projects? What steps should I take to deploy the compiled dll along with the executable? I may be going about this all wrong, so please help me understand a better methodology if this seems backwards. For all the programming I learned in college, no one ever went over what I do when I actually want to deploy my software.
Since the DLL project is explicitly referenced from the EXE project, it is automatically copied in the EXE's build folder (i.e. bin\Debug or bin\Release) and is considered part of EXE project's "primary output". As a consequence, you only need to reference the EXE from your setup project.
The installed DLL will be in the same folder as EXE. Why would you want to install the DLL in a different folder on the user's machine if it is not there on the development machine? If you are loading it dynamically and using reflection, then don't reference it from EXE, but do reference it from the setup project, which then gives you the power to set whatever target folder you want.
This is what you need to do.
On your Solution create new Project > Other project Types > Click Setup and Deployment
On The Application Folder > right click > Then Add your front end Application > Build.
Check this
Regards

how to turn visual studio windows forms project into an application?

I programmed an hour-sheet application and now I would like to publish it so people can install and run it.
I've tried the publish function of visual studio 2008 but this gives me a clickOnce application/installer that's really confusing, but it works when I run it, but when I export the installer to another pc it installs it crashes at the end of the install.
so I tried just coping the installed files but then the program crashes at startup.
Is there a simple way to compile the application to a simple standalone executable or maybe containing a separate folder containing the resources (images/classes)?
You can copy the executable from bin\Release and it should work.
If it uses any DLLs that are not part of the .Net framework itself, you'll also need to copy those. (Set Copy Local to true in the properties for each reference)
If it uses any other files, you'll need to copy them to the right place or embed them in the EXE or a DLL.
I would add Setup Project to your solution which will create a setup.exe.
Here's some of the links:
http://www.dreamincode.net/forums/index.php?showtopic=58021
http://msdn.microsoft.com/en-us/library/ms235317.aspx
This will make sure that the dlls and assemblies are deployed to appropriate place when you install your software. It will also make sure that it gets rids of files when you uninstall it.
you can find your .exe here Projectpath\bin\Debug you have to give .config file too

How can I include files in a C# deployment?

I have a DLL I need to deploy with my C# application. It's not currently included in the installation package when I hit "Publish" so how do I include it?
Would the process be any different if I had app.config and other files I wanted to deploy with my application?
If it's referenced it should be included automatically. I've deployed a couple of apps that require a 3rd party dll and they've published OK.
Is the dll referenced correctly in your project? That's the only thing I can think of at the moment that might be the problem, but if it wasn't your code wouldn't compile and/or link anyway.
To get the xls file to deploy all you need to do is add the file to the solution and then set the "Copy to Output Directory" property on the file.
I take it you are using Visual Studio?
If your using Visual Studio 2008 (I have no experience with Visual Studio 2005) under the Publish tab in your project properties click on the Application Files button. This will bring up a list of all dependencies assembalies required by your project. If you find that required dll is not being published by the Visual Studio publisher tool by default you can go into here and set the Publish Status of the offending dll to Include.
Sometimes in my more complicated projects, depending on the type of dependency, I have to go into this menu and force certain dll's to be included opposed to the default Prerequsite setting.
...but this is all under the assumption you have the assembly properly referenced in the required projects and everything is compiling fine.
Can't you add the dll as a resource to your installer project?

Categories