Error while trying to run project in VS 2012 - c#

I am creating a Windows Form application and trying to debug it.
It displays the following error:
error while trying to run project could not load file or assembly or
one of its dependencies
I updated and repaired my Visual Studio but error is same.
When I go to bin\debug and try to run .exe it shows this error:
the application was unable to start correctly (0xc000007b)

0xc000007b means STATUS_INVALID_IMAGE_FORMAT, this is an indication that your x86 application tries to load an x64 dll, or that your application target is x64, to check this you can look in the Project properties->Build->Target Platform
If your platform target is not x64 you can check your application dependencies with Dependency Walker and look if one or more of them is a 64 bit dll.

Related

ActiViz.NET.x64 (v5.8.0): Unable to load DLL 'Kitware.VTK.vtkFiltering.Unmanaged.dll'

I'm trying to use the VTK with C# to read and write VTK/VTS files. I created a basic app, and I installed the 64-bit VTK .NET wrapper package which is called ActiViz.NET.x64 (v5.8.0).
The package installed without any problems, and I could access the Kitware.VTK namespace, but as soon as I try to create a VTK object, I got an unmanaged DLL loading error.
An unhandled exception of type 'System.DllNotFoundException' occurred in Kitware.VTK.dll
Additional information: Unable to load DLL 'Kitware.VTK.vtkFiltering.Unmanaged.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I don't think that the exact code is relevant here, but I got the exception at the following line:
vtkStructuredGrid structuredGrid = vtkStructuredGrid.New();
I'm using Windows 10 x64, Visual Studio 2015, the target .NET Framework is 4.6.2 and I have ParaView 4.1 and 5.2 installed. The DLL in question is in the bin directory of the app, but I also tried to copy it to the Windows/System32 directory, the result is the same.
Is there a way to figure out what exactly the problem is with the dll loading?
If you go to the ActiViz product page you can see the following in the FAQ:
Does ActiViz 64 work with Visual Studio?
Visual Studio is a 32 bits
application, therefore 64 bits control does not work and you need the
32 bits version of ActiViz when using the designer within Visual
Studio. Usually, the 32 bits version is used to design and the 64 bits
version is used for the final compilation.
I also use VTK/ActiViz (C#) on Visual Studio, and it works fine when my program is targeting x86 platforms. However, if I target x64 platforms, the winforms control for the render window disappears, but I can still build the executable. So do this:
1) Install Activiz.NET.x86 from NuGet & target x86 platforms;
2) Create and debug your App;
3) Make a backup of the solution folder;
4) Install Activiz.NET.x64 from NuGet & target x64 platforms;
5) Don't open the designer because it will be buggy (all RenderWindowsControl disappear);
6) Build the solution (Release x64).
So, first I wanted to know where exactly is my process looking for the missing DLL. I used Sysinternals Suite and its Process Monitor.
I referenced VTK in my .NET library which I used in my self-hosted app. The self-hosted app was the start-up project, so the runtime looked for the missing DLL in the app's directory, not the library's, where it actually was.
After I copied the missing Kitware.VTK.vtkFiltering.Unmanaged.dll to that directory, Process Monitor confirmed that the DLL was read successfully, but I still got the same exception as before.
I compared the library's and the app's bin directories, and I figured that only the Kitware.mummy.Runtime.dll and Kitware.VTK.dll were copied there automatically.
I copied all the other VTK DLLs to the app's bin, and then it finally worked.
The exception's error message wasn't detailed in the first place, but I think it is more likely a problem with the ActiViz.NET package.
You should copy all dlls from Activiz Installation bin directory even you don't need to use in your code.
C:\Program Files (x86)\ActiViz.NET 5.8.0 OpenSource Edition\bin
Managed .Net DLL's is a wrapper for unmanaged VTK libraries. Mummy.dll is for this job.

An attempt was made to load a program with an incorrect format. ChilkatDotNet4. Not fixed by usual methods

I'm getting the 'An attempt was made to load a program with an incorrect format' error when trying to run a program using 32 bit version of the chilkatdotnet4 dll.
I have tried this: (setting the IIS app pool to allow 32 bit programs):
I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project
(Installed IIS first)
And the answer further down the page by Mazhar Karimi.
This: (changing the cpu target within VS):
Change target CPU settings in Visual Studio 2010 Express
This: (placing the chilkat library into the GAC for 32 bit!):
http://www.chilkatforum.com/questions/114/64bit-could-not-load-file-or-assembly-chilkatdotnet4-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format
And finally, going into the .csproj file itself in notepad and changing the Platform Target (and anything else that mentioned platform) into x86.
Edit: I have also tried going into the .dll properties and clicking 'unblock'.
After every change I have saved, built, uninstalled and reinstalled my program (c# windows service)
I am STILL getting this error!
Any ideas?
After changing your windows service to x86 this will change the build directory to
..ProjectName\bin\x86\debug
Make sure your windows service is pointing at this directory otherwise you will be running your old (any CPU) version of the service.
If you service is not pointing at this x86 directory, uninstall and reinstall the service for the new directory

MATLAB dll integration with asp.net website in 64 bit machine giving exception

I have a a problem: I have created a function in Matlab which I want to use in asp.net.
It is working fine on a 32-bit machine but when I transfer it to a 64-bit machine it is not working.
Matlab-dll integration with asp.net website on a 64-bit machine gives an exception, but not on a 32-bit machine.
Background
I'm trying to learn how to integrate Matlab code into C#. I'm using Matlab R2010a and Visual Studio 2010. I downloaded a tutorial from the Matlab File Exchange and executed the Matlab part of the code.
However, when I tried to compile the C# code in visual studio, I got the following error:
Could not load file or assembly 'MWArray, Version=2.9.1.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its dependencies. The system cannot find the file specified.
A quick google search led me to this mathworks page, which instructed me to change the target processor to x86.
However, as soon as I did so, I received a new error:
System.BadImageFormatException was unhandled
Message="Could not load file or assembly 'MWArray, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its
dependencies. An attempt was made to load a program with an incorrect
format."
My MatLab version is 64 bit, but I am still encountering this problem. Is there a workaround?
try to use this
Applications created from C# are compiled as managed code, which makes them platform independent (like Java, for example). Thus, when you compile a C# application on a 32-bit machine and then deploy it on a 64-bit machine, it will, by default, try to run as a 64-bit application. Then, it will try to find the 64-bit version of the MWArray.dll, and if it fails, the mentioned error will be shown.
To work around this issue, set the option "Properties -> Build -> Platform target" to "x86" instead of "Any CPU" before compiling your C# application. This will have the effect that the application will start in 32-bit mode on the 64-bit machine.

system.dllnotfoundexception without VS 2008

My C# code loads a C++ DLL. It works fine on my PC, where Visual Studio 2008 is installed. But on other machines the program stop with an exception
Unhandeled exception: system.dllnotfoundexception unable to load dll ...
this application has failed becasue the application configuration is incorrect....
How can I make this code run on a machine that doesn't have VS 2008 installed?
You must distribute your DLL along with your project if it is a custom DLL of yours. If not, you must install the required DLL either with a custom installer or if it is from a different provider, a installer of them.
This post might be a bit older, but
DLL Files And .NET ClickOnce Deployment
I want to deploy one of my .NET apps as a ClickOnce application. The issue is that I am connecting to Oracle (see previous posts here and here). Connecting to Oracle requires at least, 4 DLL files that generally have to be in the same directory as the EXE file. The issue is that when the program is published, the DLLs are not referenced in any way, so the program won’t work.
Then I read about adding the files to the project, so that ClickOnce and the Publish processor will figure out that the DLLs are required and add them to the manifest.
Here is the process in Visual Studio 2005:
1. Put the 4 DLL files in their own directory in your solution directory (for ease of use mostly).
2. Add all four files to your project by going to “Project->Add Existing Item…”
3. Click on each DLL file in the solution explorer and then change their property: “Copy To Output Directory” to “Copy Always”.
That’s it! Now when I publish or even run the application I don’t have to worry about if the DLL files are where they should be.
in vs 2008 on project:
Properties>c/c++ >Runtime Library > choose: Multi-threaded Debug (/MTd)

RMO on Windows 7 - The Specified module could not be found

My machine:
Windows XP (x86), VS2008, .net 3.5, sql server 2005, WinForms -> App works fine.
Production Machines: Windows 7 (x64), SQl Server 2005 Express -> App Starts but throws exception
Visual Studio Targeting x86 on setup project and RMO project. Visual Studio gives me a a couple warnings but I can still build:
Unable to find dependency 'MICROSOFT.SQLSERVER.MANAGEMENT.SQLPARSER' (Signature='89845DCD8080CC91' Version='10.0.0.0') of assembly 'Microsoft.SqlServer.Smo.dll'
Unable to find dependency 'MICROSOFT.SQLSERVER.MANAGEMENT.SQLPARSER' (Signature='89845DCD8080CC91' Version='10.0.0.0') of assembly 'Microsoft.SqlServer.Management.SmoMetadataProvider.dll'
This is a simple RMO (Replication Management Objects) app that initiates a pull subscription in SQL Server 2005 and displays status. Works fine on my machine, but fails on the production machine. I'm using a setup project to install the app on the production machine, but I think I'm missing a dependency somewhere, but I can't figure it out.
On the production machine the app starts fine, but when I try to synch the subscription i get:
System.IO.FileNotFoundException: The Specified module could not be found. (Exception from HResult: 0x8007007E)
EDIT: Task Manager in Win 7 inditcates that it is running as a 32-bit app (myapp.exe *32).
EDIT: Ok, my app is now showing in task manager that it is a 64 bit app, but I'm getting an error. I'm thinking that I some how have a dependency dll targeting x86. How can I verify the dependency dll is targeting the correct platfrom and/or make sure that it is targeting x64... I thought the setup prjoect would rebuild the dll in my detected dependencies to target whatever cpu I chose in the setup project?
Could not load file or assembly 'Microsoft.SqlServer.Replication, Version=10.0.0.0, Culture-neutral, PublicKey Token=89845dcd8080cc91' or one of its dependencies. An attempt to was made to load a program with an incorrect format.
run Fusion Log viewer as administrator and set it to Log Bind Failures to Disk.
that way you'll be able to see which DLL's don't load properly.
I thought the setup prjoect would rebuild the dll in my detected dependencies to target whatever >cpu I chose in the setup project
the setup does not compile any dlls for you automatically.
An attempt to was made to load a program with an incorrect format.
look here, on where to find an x64 version of 'Microsoft.SqlServer.Replication'
http://social.msdn.microsoft.com/Forums/en/sqlreplication/thread/628ec2ae-c5d1-4aef-b31b-b889975bfc2b

Categories