Convert x86 VSTO PowerPoint Add-in to x64? - c#

I have a VSTO PowerPoint Add-in project complied with default mode. Which works fine. Now I have to use a reference NeedleSeekAPI.dll, but it seems it was complied with x64 mode.
So the problem is if I choose Any CPU I will have error:
Could not load file or assembly 'NeedleSeekAPI' or one of its dependencies. An attempt was made to load a program with an incorrect format.
And if I choose X64 I have another error:
Could not load file or assembly 'PPTSearch, Version=1.0.0.0, Culture=neutral' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
I tried to convert my VSTO Add-in project into 64-bit follow this article:
http://blogs.msdn.com/b/vsto/archive/2010/04/09/deploying-com-add-ins-for-64-bit-office-using-visual-studio-saaid-khan-for-nathan-halstead.aspx
but it is not working as well, I still get the same error. (or do I have to revised my VSTO PPT addin to a Shared-addin?)
I use VS2010 with .NET framework4.
Do you have any suggestion?

You can try spawning a different process to handle calls to 'NeedleSeekAPI.dll' which is compiled in a different mode.
You need to handle inter-process communication, if NeedleSeekAPI.dll is editable you may pass parameters to it when spawning the process.

Related

Could not load file or assembly 'Microsoft.SqlServer.Replication

I have an c# application using 'Microsoft.SqlServer.Replication .NET Programming Interface DLL.
(Microsoft.SqlServer.Rmo.dll)
I need there the TransSubscription and TransPublication.
I can build the solution without any error or warning, and run it in Debug and Release mode on my computer. But if I would like to start the release application an another computer, i receive the error:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.Replication, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.SqlServer.Replication, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
I tried it to have as x64 and x86 application, no affect. I cannot interop the DLL, there will be errors in Vistual studio.
Anyone has an idea?
Thank you
Edit:
Meanwhile i did some more testing..
I have installed on a new VM SQL server to get only the available, and in the rght version dll. Installed VS and build the project. This was sucessful, no errors. But if i am starting the app, already in debug mode it crashed with the same error code. any idea?
The dll is referenced all build is completed.
Edit:
According: https://learn.microsoft.com/en-us/sql/relational-databases/replication/concepts/replication-management-objects-concepts?view=sql-server-ver15 i need to add Replication Agent Library (REPLAGNT.dll) but this i cannot do in VS, "A reference to .... could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component". What do i do wrong?
For me it sounds like you referenced a dll which is located in a local folder, which works okay as long as you are working on your machine, but crashes as soon as you using another machine. After a build/rebuild a dll should be located in the bin folder.

C# COM-Interop dll for C++ COM dll doesn't work between 2 solutions

I am trying to reuse an interop DLL that compiled in one project on another, and it doesn't work.
I'll elaborate:
I compile the C++ COM DLL native_com_object.dll
In the same solution I have a C# project called LocalComClient.dll that generates Interop.native_com_objectLib.dll to use the C++ native_com_object.dll.
Last, I have another solution with a C# project (being compiled on another computer) called RemoteComClient.dll that references to native_com_object.dll (registered in that computer). This generates another Interop.native_com_objectLib.dll.
The problem is RemoteComClient.dll tries to load native_com_object.dll it MUST use its own Interop. If I try to use the LocalComClient.dll Interop .Net fails to load the assembly.
Edit: The exact exception message I am getting is:
Could not load file or assembly 'Interop.native_com_objectLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Of course the problem also occurs vice-versa (LocalComClient cannot use RemoteComClient's Interop).
My first question is - why?? As far as I understand it should generate the same interop (which obviously I am wrong).
My second question is, is it possible to make one interop for all the .Net clients of the DLL?
I'll point out I am using VS2013 (both machines), the C# objects are AnyCPU, and the C++ is x64.
Important EDIT: I cannot embed interop types because the C# projects are .Net 3.5 (not 4).
The located assembly's manifest definition does not match the assembly reference.
Very common exception message, the DLL it finds at runtime isn't the same as the reference assembly your program was compiled with. A very basic DLL Hell problem, not otherwise specific to COM interop.
You diagnose these kind of failures with Fuslogvw.exe, its trace for the failed assembly bind shows you what it looked for and what it found. The usual mismatch is the version number, you compiled your program with the 1.0.0.0 version of the interop assembly. That version is generated from the type library version number of the COM server. You were using version 1.0, kaboom if the COM server changed and you use its newer interop assembly.
And the PublicKeyToken can easily be a mismatch, you expect the interop DLL not to have one. Kaboom if the one you load at runtime does have one. Not terribly uncommon in COM interop, you tend to favor them getting stored in the GAC and that requires a strong name. Something you usually do later, forgetting to rebuild the app is an easy mistake.
The solution is to rebuild the client app with the correct interop assembly.

.NET exe not picking dll dependencies

I have developed an EXE again :)
The problem is it has refernces of SQLite dll file so I included the file on the same path. Now in Windows 8 it is running fine, but in Windows 7 it is not
The error is
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.90.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)
File name: 'System.Data.SQLite, Version=1.0.90.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' ---> System.Runtime.InteropServices.COMException (0x800736B1): The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
I did everything I could but it is not running on Windows 7
It's a standalone EXE. No Setup.
EDIT:
This is what application event log says
Activation context generation failed for "C:\System.Data.SQLite.dll". Dependent Assembly Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195" could not be found. Please use sxstrace.exe for detailed diagnosis.
I think thats the reason as you mentioned, SQLLite is searching 64 bit dll!
Try to download 64 bit url and pack it with exe
You can download from here
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
side-by-side configuration is incorrect
That means Either:
One of your reference DLLS do not match your project target type
Or Your reference DLLS are of mixed target types
Solution:
Make sure your Project is set to build to target x86 for x86 reference DLLs or target x64 for x64 reference DLLs, and the same for the .NET versions
Make sure all your reference DLLs are either all x86 or all x64 versions and not x86 and x64, and the same for the .NET versions
If you are not sure you can use IlSpy to check by right clicking on the reference.
Generally this error indicates that a dependent assembly is missing.
Activation context generation failed for "C:\System.Data.SQLite.dll".
Dependent Assembly
Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195"
could not be found. Please use sxstrace.exe for detailed diagnosis.
This assembly is more commonly known as
Microsoft Visual C++ 2005 Redistributable Package (x86)
and can be downloaded from here.
But, often there is another cause. Today, for us, it was "Bit9 Security" which did not like us digitally signing the SQLite.dll assembly on our local machine and uploading the signed assembly to our server application folder with a different time stamp to the rest of the assemblies in the application folder.
The work around was to recompile the application, sign all the assemblies, upload and overwrite the existing application files.

c# app can't find dll in its working directory

I just switched from C++ to C# and I am a bit confused about referencing DLLs.
I have a third party DLL and a simple testing application that uses some of its methods. When I compile the project, everything goes well, but when I run the compiled app on another computer, I've got an error that says that the DLL is missing even though the DLL is in the app's working directory. What's even more strange is that I have access to the source code of another app that is dependent on an older version of this DLL and this app works well.
I've gone through the code and all the solution settings without finding anything really different.
Can you tell me how to reference a .dll from a working dir (Visual Studio 2010)?
Below is the exception:
System.IO.FileNotFoundException was unhandled
Message=Could not load file or assembly 'TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928' or one of its dependencies. The system cannot find the file specified.
Source=ICtestapp
FileName=TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928
FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
StackTrace:
at ICtestapp.Form1.InitializeComponent()
at ICtestapp.Form1..ctor()
at ICtestapp.Program.Main()
InnerException:
Here's a good blog post from Suzanne Cook from the .net team on debugging .net loader issues.
http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx
and here's the details on how it loads:
http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.71).aspx
You have to add the dll as reference in your project references, once you added the library in the reference, when you compile the program the dll will be automatically copied to the compilation output folder unless otherwise specified in the reference properties ...
Then if you copy all items that you will find in the compilation output folder in the new location in the other PC, you should not have any problems.
Check also that the .NET framework installed on the other machine is at least as the same level of the project target ..
This also happens when you copy the debug executables over to another machine. Try compiling in release and moving over.

C++/CLI/C# BadImageFormat Exception when loading form

I created a C++/CLI assembly that creates a wrapper around native C++ code. The resource compiles and the assembly loads fine into my C# project when I add it as a resource. I can access my objects and intellisense from within my application, but when attempting to build, it crashes with the exception:
BadImageFormat
Could not load file or assembly
'MyCLI, Version=1.0.3680.28432,
Culture=neutral, PublicKeyToken=null'
or one of its dependencies. An attempt
was made to load a program with an
incorrect format.
I load it into my form load event:
MyCLI.myCLI z;
... and when I compile, it crashes on this line in my main constructor in C#
Application.Run(new Form1());
Does anyone have an idea of what could be causing this exception?
Thanks
You are trying to run this code on a 64-bit operating system. Your C# code will get nicely compiled to 64-bit machine code. But you'll hit the wall when it tries to load a 32-bit C++/CLI assembly.
In the C# project, use Project + Properties, Application tab, Platform Target = x86. Creating a 64-bit version of your C++/CLI assembly is possible too, use Build + Configuration Manager. Using Platform Target is the better solution.

Categories

Resources