Building for x86 and 'Any CPU' - c#

I am trying to use Microsoft.Jet.OLEDB driver to connect to an access database from my C# application. When I try to open a connection, I get an error: "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine." This is because the driver is only supported on 32 bit machines.
My solution was to change the platform target of the project that references it to x86. If I try to change all of my projects to x86 I get major build problems, so I am leaving them all on 'Any CPU'
Problem now is when I start up in VS, it tells me: "Could not load file or assembly 'MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."
I've tried about every configuration I can think of and I just can't quite get it to work. Any tips?

You'll have to switch the whole thing to x86. As you've found, there isn't an x64 driver for Access.
Your other code, if compiled x64, can't use x86 assemblies. You might want to review this question: Can an x64 application use x86 assemblies - and vice versa?
UPDATE
Interestingly, I found the Access Database Engine x64 from MS. You might try to grab that and see if it will work for you. You might also check out this discussion on MSDN.

You do have to switch to 32-bit to use Jet. (Edit: unless you use the new driver a couple of other posters have referenced).
If any one of your projects is using image lists, there is a bug that will cause errors when switching from 64-bit to 32-bit. As I recall you either have to rebuild the image lists from scratch or drop them and use something else instead.
You can find more info here and here.

Related

.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.

"Could not load file or assemly" "The specified file could not be found" exception

I'm trying to run a C# program on another computer, and since I was experiencing some troubles running the program, I put everything in the "window.initialized" event inside of a Try-statement.
When I then run the program on the other computer, I get an exception saying that "System.Data.SQLite.dll" cannot be found, even though it's sitting right in the debugfolder where the .exe I'm executing also is located. This feels very weird and I have no idea how to solve it.
Anyone got an idea?
Here are three points which I know to cause this issue:
a) As said in your comments, the assembly reference points to another version than the one of the file in the program directory.
b) The application is targeting a different platform than the assembly (i.e. x86 vs x64). I'm not sure, but it might cause the app to work on one machine and not on the other, when one assembly is built against 'Any CPU' and one against a specific platform (x86 or x64).
c) The referenced assembly is targeting a .NET framework version which is different from the on of the application itself and which is available on the development machine, but not on the other machine. This will cause an assembly binding exception. To check, have a look at the property window after selecting the assembly in question:
Not sure whether there are more, but I hope it helps.

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.

BadImageFormatException when attempting to use LuaInterface

I imported LuaInterface into a console project, referenced it, and wrote a small test script. When i run it, i get this:
Could not load file or assembly 'LuaInterface, Version=2.0.0.16708, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Forgive me for being a newbie or something, but i can't figure out what it means. What am i supposed to do?
Are you running on a 64-bit operating system?
If you are then you'll need to either get an x64 build of LuaInterface or set the platform target of your console project to x86.
You can read up on the platform target option here:
http://visualstudiohacks.com/articles/visual-studio-net-platform-target-explained/

Assembly references won't resolve properly on our build server

We code in C# using VS2008 SP1. We have a server that runs Team System Server 2008 which we use for source control, tasks etc. The server is also our build machine for Team Build. This has been working just fine for a long time. Untill now. We get these error messages when trying to build one of our projects that has a reference to one external assembly (this happens both via Team Build, and when logging on physically and doing a regular build via Visual Studio):
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets
: warning MSB3246: Resolved file has a
bad image, no metadata, or is
otherwise inaccessible. Could not load
file or assembly 'C:\Program
Files\Syncfusion\Essential
Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
or one of its dependencies. The module
was expected to contain an assembly
manifest.
C:\Program
Files\MSBuild\Microsoft\VisualStudio\v9.0\ReportingServices\Microsoft.ReportingServices.targets(24,2):
error MSB4062: The
"Microsoft.Reporting.RdlCompile" task
could not be loaded from the assembly
Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a. Could
not load file or assembly
'Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The module
was expected to contain an assembly
manifest. Confirm that the
declaration is correct, and that the
assembly and all its dependencies are
available.
The referenced component
'Syncfusion.XlsIO.Base' could not be
found.
These errors are for one project with one problematic assembly reference. When I try to build the entire solution there are of course many more errors because of this one. And there are two other projects that has the same problem with other assembly references. I have a list of the referenced assemblies that VS can't seem to resolve:
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WinForms
Syncfusion.Compression.Base
Syncfusion.Core
Syncfusion.XlsIO.Base
The Syncfusion assemblies are from a 3rd-party component package. The other two are related to the Microsoft ReportViewer component.
The references has been added via the Add Reference window, in the .NET tab, so I don't think there is anything suspicious about that. In the properties window for the assembly reference, there is no value in Culture, Description, Path, Runtime Version or Strong Name. Version says 0.0.0.0 and Resolved is False. I guess it is pretty obvious that VS cant resolve the reference. My question is why??? I've scratched my head a lot over this one. This only occurs on the server, the solution builds just fine on both my machine, and my coworkers machine. The assembly reference properties are fine on our machines.
I have tried uninstalling the 3rd-party component (on the server of course), and then reinstalling it again. Didn't help. I tried to repair the VS2008 installation. Didn't help. Tried to retrieve an earlier version from source control (that I know has buildt on the server before), and I got the same error messages. I have checked file permissions, and everything appears to be in order. I am running out of ideas...
How do I solve this?
Update 16.02.2009:
I have tried to compare ildasm output of the dll on my pc and on the server (see the comment I wrote about that), and there is one small difference in a line that to me appears to be a comment. I must admit that I don't understand why there is a difference at all, so maybe someone could explain that to me?
I also tried running a virus scan on the server. Didn't help. Tried to remove the reference and then readd it by browsing to the dll on disk. Didn't work.
Update 17.03.2009:
I've found the solution! The culprit was the TruPrevent module of Panda Antivirus. After disabling the module, everything works! =)
I discovered this with the help of fuslogvw.exe and the log it generated. Googled the result, and stumbled upon this blog entry.. Hope this can help somebody else to.
Almost certainly the problem is environmental - not source related.
Some ideas ...
(i) Try disabling your anti-virus/anti-malware tools - I've seen cases where these tools (particularly Trend Micro Antivirus, for some reason) can keep a DLL file locked after (during?) scanning, interfering with compilers.
(ii) Check your PATH environment variable. Even in these modern days, the PATH variable is used to resolve some things - if this is messed up (too long, maximum length is 2048 characters IIRC) then things can be odd.
(iii) You've checked File permissions - have you checked permissions in the registry? For example, SyncFusion installs its license key in both the User and Machine hives - if the build server can't read one or the other, could cause issues.
Good luck!
It could also be that the referenced assemblies are in the GAC on the dev machine, but not on the build machine. Get it out of the GAC, into your source repository, and reference it by path.
We've had the same problem, turns out the C drive was full (only had 28MB).
Freeing space resolved the issue, even though the build happens on D.
Do you see any differences between ildasm of this file
'C:\Program Files\Syncfusion\Essential Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
on your machine versus on the server?
My suspicion is that the user that the build process is under does not have access to the folder that your 3rd party control is in. Since this functions properly on your machines, it is almost certainly user/permission specific.
Your 3rd party dll may depend on unmanaged dlls. Often it's because a specific version of the VC++ Runtime Dlls are missing.
Open the Dll with the Dependency Walker http://www.dependencywalker.com/ on your server and check for missing references.
Not sure if this'll help in your case, but I did have something similar before where a dll apparently got unregistered somehow, and running regsvr32 on the dll did the trick.

Categories

Resources