Error when creating Excel document using NetOffice Interop - c#

I am getting the following unhandled exception when I try to create an excel document using my c# application. This process works fine when I am running the c# application from visual studio 10, but when I try to run the application outside of visual studio using the .exe file this error is appearing.
System.IO.FileNotFoundException: Could not load file or assembly 'ExcelApi, Version=1.5.1.2, Culture=neutral, PublicKeyToken=9084b9221296229e' or one of its dependencies. The system cannot find the file specified.
File name: 'ExcelApi, Version=1.5.1.2, Culture=neutral, PublicKeyToken=9084b9221296229e'

Apparently your project has an assembly called ExcelApi.dll which is missing on the target machine. I assume this is a NetOffice dll, which is required in the output directory for your project to run.
Open your project directory (depending on your VS version, you can right-click the project in Solution Explorer and choose Open Folder in Windows Explorer). Go into the \bin folder, then into the folder that matches your build configuration (most likely Debug, but it might be something else depending on how your project is set up). In that directory, copy all of the .exe, .dll, and .config files to the directory you're trying to run your program from.
In particular, you will need at a minimum your executable and config file, along with ExcelApi.dll, OfficeApi.dll, VBIDEApi.dll, and NetOffice.dll. See here for details.

Related

Export or execute a console application form project

How do you save your console application as exe program?
I have found the exe file within the Debug folder, but returns an error when executed.
Error message –
Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. The system cannot find the file specified.
I’m using the Ionic library, I think I need to package the whole program, not sure how to do this?
Right click on the your project on the solution explorer
On configuration choose release
Now you will find a release folder next
to the debug folder use the .exe inside it

How to set the current\working directory of a WPF application to the installation path

In my C# WPF application I need to access some configuration files via a 3rd party library. This library requires to have the configuration file located in the same folder as the executable of my application. So i have no chance to change this behaviour.
While running my application in Visual Studio 2013 it works fine. I can access the configuration file since I have just copied it to the relevant folder.
But if I install my application an run it it cant locate my configuration files because it tries to find it under: Windows\system32.
No my approach is to make it happen that my application looks for the configuration file in the applications install folder.
How can I do that? How can I set the current\working directory of my application to a specific (installation) path in Visual Studio 2013?
try this
string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
This will give path like "c:\\program...\\installdir\\" where your .exe is located.

Referencing dll files - my AutoCAD plugin only works on my computer

I have created an AutoCAD plugin, but encounter problems when using the plugin on certain machines. It works fine on my machine.
One thing that I have noticed is that if I change the output path of the build to a different directory I get problems stating that certain namespaces cannot be found.
The following shows the build output folder with the dll files in, the build is successful.
http://imgur.com/5va3ePj
However, if i build to an empty folder (even with dll files referenced) i get the following errors and warnings...
http://imgur.com/eM86l0u
This plugin needs to be able to be used by other users, i think im not referencing dll files properly or something as the program only runs successfully on my computer (and all computers that i have opened the solution in visual studio and built to the export folder). Copying all the files shown in the folder above to the same path on another users computer doesn't work, other users get an error stating 'Could not load fil or assembly "c:/info3d/info3dreloaded.dll" or one of its dependencies. Operation not supported. Exception from HRESULT: 0x80131515)'
Thanks in advance for any help!
Chris
For AutoCAD DLLs set the Copy Local to false. AutoCAD provides those via its runtime.
"Once a AutoCAD .NET API DLL is referenced, you must set the Copy Local property of the referenced DLL to False." from http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-8657D153-0120-4881-A3C8-E00ED139E0D3-htm.html
Right click on the reference and click on properties and set the "copy local" property to true

Regasm.exe only works in Debug output folder, not install folder

I am writing an add-in dll in c#, VS2012, Win 7 x64. Debugging has been fine; VS registers the dll at the end of building and I've also set up a batch files in my project folder to register and unregister the assembly.
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe" /codebase ".\bin\Debug\MyAddin.dll"
This will work every time. FYI my development files are also on a network drive and they will register. Even changing to an absolute file path for the dll works.
Now I am working on deploying the add-in, so I'm starting with WIX to create the installer MSI to put the files in the correct install folder. This is where I start getting the RA0000 "Unable to locate input assembly 'MyAddin.dll' or one of its dependencies." error from regasm.exe when I run from a batch file in in my project folder to register the files once they are installed.
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe" /codebase "C:\Program Files\Suite Folder\Product Folder\MyAddin.dll"
This never works. I could see if regasm never worked, but anywhere outside of the output folder won't. So here is what I've tried so far.
Since my Debug output folder has other files like the .tlb and other stuff I started deleting them one by one all the way down to my add-in and the dependent .dlls. Just to verify what files are really needed to register in the output folder.
I thought maybe WIX was not creating the files correctly so I copied all the files including the .tlb and others from my output folder into the install folder (I know these should not impact anything but just to be thorough)
I've unregistered the dll after VS builds thinking that more than one register was the problem.
Tried running regasm from within the install folder directly so it could find all dependencies there.
Made sure all of my dlls are x64 platform.
Tried all lines from batch files in CMD window (w/ and w/o run as admin).
File attributes from output to install folder are the same.
Any ideas?

Can not load the CLIPSLIB.dll file with Windows Service

I am working with developing Windows Service using C#. I want to load CLIPSLIB.dll with Windows Service. First I tried write service as console app in vs2010 placing CLIPSLIB.dll in the project debug folder. It worked fine.
But when I install it and run as Windows Service it throws this exception.
Could not load file or assembly 'Mommosoft.ExpertSystem, Version=0.3.0.2, Culture=neutral, PublicKeyToken=20382083c6694bdc' or one of its dependencies. The system cannot find the file specified.
As I figured out this is happening because Windows Service is unable to load relevant dlls. So whare should I put external dlls to load with Windows Service?
Scott Hanselman has an article that describes how to debug assembly loading errors. the downside to this method is that it requires a registry key change and a reboot in order to emable the fusion loader logging.
That article can be found here:
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx
since you are writing a windows service check that the reference for the assembly refers to the bin directory and not some other path. Otherwise the fusion loader logs will identify where it is trying to load the assembly from.
as to the .dll files add a folder to your project and add the .dll files there, change the build properties from do not copy to copy if newer in order that the .dll files will end up in your build output bin path.
You must rebuild the CLIPSLib solution,
Download all files in this link :
Link: https://svn.code.sf.net/p/clipsnet/code/
2.Open CLIPSLib.sln in CLIPSLib folder
3.Right-click on the solution and select rebuild solution.
4.Go to the CLIPSLib folder your CLIPSLib.dll and CLIPSNet.dll is in ..\ ..\mlplatform\bin floder.
hope this help.

Categories