System.Data.SQLite BadImageFormatException with NHibernate, works finewhen standalone - nhibernate

I tried to use NHibernate with SQLite,
version=1.0.74.0 for .NET 4 and 32 bit.
I use a 64bit WIN7, but build the application in x86 mode
(default in VS2010 express).
When I use the same SQLite as a standalone application it works fine, but when
I try to use it with NHibernate it throws BadImageFormatExcepion
I debugged a bit NHibernate and the Exception is thrown at the folllowing statement
System.Type.GetType("System.Data.SQLite.SQLiteConnection, System.Data.SQLite");
Any chances somebody knows the solution?
Is it because I use default mode in VS Express?
Do I need to specify platform using some other method?
try to download some other dll for sqlite?
I checked some other answers on SO thebest I got was
to add to my app.config this:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
</DbProviderFactories>
</system.data>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>

If VS express does not allow you to choose a platform you can try setting it up manually in .csproj file
<PlatformTarget>x86</PlatformTarget>
After building your app make sure that:
it is executed as 32 or 64 bit app depending on what you put in PlatformTarget (using Windows Task Manager or Process Explorer)
the right version of SQLite.Interop.dll is copied to the folder where you have your exe (this dll is platform dependent, so you need to copy the version corresponding to EXE platform)
Corresponding version of Visual C++ 2010 SP1 Redistributable Package is installed
Also try removing useLegacyV2RuntimeActivationPolicy from config.
From BadImageFormatException doc:
... A DLL or executable is loaded as a 64-bit assembly, but it contains
32-bit features or resources. For example, it relies on COM interop or
calls methods in a 32-bit dynamic link library. ... To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.

Related

only supports language versions up to Visual Basic 2012

[EDIT: It is a memory issue. The memory on my computer goes from 42% used to 91% in a few seconds just before this error. The error message about the compiler supporting up to 2012 is just a red-herring. That message is always output from the compiler. ]
I just converted a visual basic application from VS2005 to VS2017.
I get this error when I try to start it:
Server Error in '/' Application.
Compilation Error Description: An error occurred during the
compilation of a resource required to service this request. Please
review the following specific error details and modify your source
code appropriately.
Compiler Error Message: The compiler failed with error code
-2147024888.
Show Detailed Compiler Output:
C:\Program Files (x86)\IIS Express> Microsoft (R) Visual Basic
Compiler version 14.7.2556 for Visual Basic 2012 Copyright (c)
Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework,
but only supports language versions up to Visual Basic 2012, which is
no longer the latest version. For compilers that support newer
versions of the Visual Basic programming language, see
http://go.microsoft.com/fwlink/?LinkID=533241
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.7.2556.0
Here is what I tried:
Followed the fwlink and it actually redirects to github that appears to be some open source version of the compiler that will support my old code. I have no interest in doing that.
Reading the answers to this question: Compilation Error when change .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition
I tried to follow the instructions, but those instructions seem to be for a MVC project and my project is a Web project [Note: I am new to Visual Studio so I probably have that wrong] but what I am sure of is:
a. I don't have a project file.
b. I see a globe icon on my project.
c. When I right click on the project (globe icon thing in solution explorer) I do NOT get a Properties menu item.
So, how do I get past this error where my preference is to update my code to current techniques rather than patch together libraries to get it to run.
[EDIT] This problem just occurred on a different project/solution that actually does have a project file. This was converted from VS2005 to VS2017 a couple of months ago and has been working fine. I suspect some configuration change in VS2017 that is affecting all solutions.
[EDIT] The comment about out of memory seems promising except it fails in exactly same spot every time. A reboot did not help. This is an i7 with 16GB and 500GB SSD with 400GB free. If it is running out of memory it might be some config in VS that artificially limits memory of that particular process. I am going to deeper into this lead.
[EDIT] I have IIS Express 10.0.1740 installed.
[EDIT] I tried installing the Roslyn compiler using nuget. The error message did not change, but it could be I need to do some additional config to get it to be the compiler used for this solution/project. The problem is happening while the application is running so presumably iisexpress is doing the compiling.
[EDIT] This is also happening on a different project that does have a .vbproj file. I suspect some update that is causing the issue.
[EDIT] I am now testing in a project that has a .vbproj file. To change target framework I do Project -> XXX Properties -> Application -> Target Framework 4.6.1. The problem still happens. Note the warning in the message that it may require additional hand edits. I did not know what to edit, so I did not make other changes.
[EDIT] Note that the compiler version is 14.7.2556 And it is complaining about being for VB2012. This seems to conflict with https://en.wikipedia.org/wiki/Visual_Basic_.NET that says that vb compiler 14.0 came out in 2015.
[EDIT] I did not have a section in web.config, so there is nothing to remove.
[EDIT] I do not have a compilerOptions= tag in web.config, so there is nothing to change.
With a an i7 with 16GB and 500GB SSD with 400GB free I doubt this is a memory issue, I'm guessing the ERROR_NOT_ENOUGH_MEMORY is a symptom of the root cause:
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to Visual Basic 2012,
In other words the compiler only works with projects upto 2012, so lets just change what commpiler we use by targeting an up-to-date version of the .Net Framework (right click on Project > Property Pages):
You also can safely remove the CodeDom that's used for Dynamic Compilation in the web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
Or you could change the compilerOptions="/langversion:6 compiler version.
If this doesn't work, make a cut down https://stackoverflow.com/help/mcve in VS2005 that we can reproduce the problem with and upload the solution somewhere we can download it.
#jmcilhinney you were on the right track. I worked with #Michael Potter and found that, on the local machine, IIS is having trouble doing the just-in-time compile a "Website" requires. I've no deeper knowledge than that (and not sure I want any) but the issue was fixed (in this case) by switching to HTML pages (it is mostly a SPA site).
Had we more code-behind than we do, I would simply switch to a "Web Application".

System.IO.FileNotFoundException with Pivotal.Gemfire.dll

I am installing a C# windows service that uses Geode onto a UAT Windows 2012 server. The referenced dll (like log4net, newtonsoft.json and QuickFix) are working except for Pivotal.Gemfire.dll
When I start the service I get System.IO.FileNotFoundException: Could not load file or assembly 'Pivotal.Gemfire.dll' or one of its dependencies. The specified module could not be found. File name: 'Pivotal.Gemfire.dll'
Now Gacutil doesn't come with Win Server 2012. I've tried installing Windows SDK and .Net SDK and not found a Gacutil executable. So I've tried to get in the dll into the GAC using powershell like this:
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("D:\Pivotal.Gemfire.dll")
I've tried regsvr32 Pivotal.Gemfire.dll in various flavours
I've tried compiling and running the GacInstall executable at https://github.com/apache/geode-native/tree/develop/executables/GacInstall. It says Installation completed successfully. but when I try to run the service, or try powershell:
([system.reflection.assembly]::loadfile("D:\Pivotal.Gemfire.dll")).FullName
I get the same error.
I've tried a private assembly using runtime assembly binding
<runtime>
<assemblyBinding
xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Apache.Geode" publicKeyToken="null" culture="neutral" />
<codeBase version="9.1.1-build.2" href="file://Pivotal.Gemfire.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
and various flavours of name Pivotal.Gemfire, Apache.Geode.Client according to Implementing Shared Assembly but always the same error.
Any ideas? Thanks...
UPDATE: Make sure you have x86 and x64 bit C++ packages back to 2013 (for older versions of Geode Net client)
I downloaded the previous version of Geode, 9.0.7, called Gemstone.Gemfire.Cache.dll and got the same error, but that version included a Gemstone.Gemfire.Cache.xml in the same directory. If I took the xml file to my bin directory the error stopped and the service started properly.
So like this the problem is a redundant accompanying xml file to the dll. I fixed the issue by creating a new dummy xml file Pivotal.Gemfire.xml
<?xml version="1.0"?>
<doc>
</doc>
For me the marked answer did not work.
I had to download DependencyWalker which showed me why the Pivotal.Gemfire.dll was not working. One of missing DLLs was from:
Visual C++ Redistributable Packages for Visual Studio 2013
After installing 64x bit, application started to work.
This problem happened again with another install. The answer above using the xml file did not resolve it, it was resolved by downloading version 9.0.7 of the Native Client, Gemstone.Gemfire.Cache.dll and then running
.\gacutil /if C:\Gemstone.Gemfire.Cache.dll
which returned Assembly successfully added to the cache then removing the earlier version of the dll, but retaining the later version Pivotal.Gemfire.dll that I could not get into the GAC because of a strong name issue. This bizarre workaround of getting the earlier version of the dll into the GAC allows the GAC to find - and use - the later version...
This happened to me again with a Geode Native built locally, when it is run on a new Windows 10 install the dependency walker shows missing MSVCP140D.DLL VCRUNTIME140D.DLL and UCRTBASED.DLL as here
The D is related to having built the client in debug mode.
The problem is related to How can I install a Visual Studio C++ redistributable if it is missing? and the answer is either to get a release build of your dll, or to go to Visual Studio Installer, Modify, navigate to Individual components -> compilers, build tools, and runtimes, and check the MSVC v 140 VS 2015 C++ build tools
Yet another time this happened to me and I had to remove references and files to Apache Geode dll built as native client, then reference them all again.

WIX CustomAction loading CLR 4.0 instead of 2.0

I'm trying to write a c# custom action and using .Net 2, however I can't seem to get things to work. I believe the MSI is using the wrong CLR version. I see this in the log file a few lines above where the MSI is calling my CA (line line does not appear if I comment out my CA):
SFXCA: Binding to CLR version v4.0.30319.
My custom action does not appears to load (assuming since I do not see any of the logging messages). I am using Wiz 3.6.3014.0. Is this supported or does the Windows Installer just use the latest runtime available on the machine?
Thanks
When you use WiX to create a C# custom action project, it by default creates an XML file called CustomAction.config. The purpose of this file is to instruct sfxca.dll what version of the CLR to use when running your code. The default implementation of this file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, #useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>
Basically it's a good practice for CA's written in .NET 2.0/3.0/3.5 ( all CLR 2.0 ) to be allowed to run against 4.0 because you could come across a machine that has only 4.0 installed. Generally your code should work against 4.0 and if it doesn't, I'd fix that.
Alternatively you could update the config file to only allow running on 2.0 and then put the needed checks into the installer to make sure that this version of the CLR is infact installed.

How to successfully host ASP.NET MVC4 RC on Mono 2.10.8

I'm trying to host a ASP.NET MVC4 RC project on top of Mono 2.10.8.1. I'm getting the following exception when I access the app for the first time:
Missing method System.Web.Security.FormsAuthentication::get_IsEnabled() in assembly /usr/lib/mono/gac/System.Web/4.0.0.0__b03f5f7f11d50a3a/System.Web.dll, referenced in assembly /tmp/root-temp-aspnet-0/eaee30a1/assembly/shadow/5cf10065/40974e7d_1c664e18_00000001/System.Web.Http.WebHost.dll
According to http://www.mono-project.com/Compatibility this should be implemented in Mono 2.10.8. Microsoft lists the property as .NET Framework 4.0: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.isenabled.aspx
Is there a work-around of some kind, or is it just not possible to host MVC4 on Mono at this time?
I should note that I'm getting this problem both when using XSP4 and mod_mono on Apache2.
Mono version is the following:
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
TL/DR: Running MVC4 under Mono is still not recommended, run MVC3 instead.
Long story: at the time Mono 2.10.x was released, Microsoft had not fully released the ASP.NET stack as open source (Razor was one of the components that was still closed source).
Recently Microsoft finally opensourced the full stack, and Mono has included it in their tree, however this has happened only in master branch (and only preview versions of Mono 2.11.x include it). Besides, the async APIs are not yet implemented in Mono (and MVC4 depends on them) so then the best bet for you is use MVC3 for now, with Mono 3.0.1 version.
Even longer story: http://tirania.org/blog/archive/2012/Mar-28.html
It is now possible, and is almost straightforward on the current mono release and using NuGet. The fact that MS have put MVC4 stuff on NuGet helps. I've put working templates for .Net 4 & .Net 4.5 on github https://github.com/chrisfcarroll/AspNetTemplatesForMono. There are a couple of gotchas, but they're addressed in notes.
You need to compile the new XSP form the sources
git clone git://github.com/mono/xsp.git
cd xsp
./autogen.sh --prefix=/opt
make
sudo make install
This version needs enough permission to run, sudo..., otherwise you will get the System.IO.FileNotFoundException message.
Then add these lines to your web.config file
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
To eliminate CS0234: The type or namespace name Helpers does not exist in the namespace System.Web. exception.
Then remove these assemblies from your bin folder (if those are copied form the Windows machine)
Microsoft.Web.Infrastructure.dll
System.Net.Http.dll
System.Net.Http.Formatting.dll
System.Web.Http.dll
System.Web.Http.WebHost.dll
This will remove Missing method System.Web.Security.FormsAuthentication::get_IsEnabled() exception and many other could not load type xyz exceptions.
Please follow below link to host MVC 4 Application on Mono successfully.
http://www.bgsoftfactory.net/run-asp-net-mvc-4-with-mysql-on-linux/
It provides step by step configuration on Linux server.
Remove reference to System.Web.Http and System.Web.Http.Host if you do not need them (WebApi library).
You may need to remove WebApiConfig.cs in the App_Start folder and the references in the Global.asax.
But after that your project will work without any other issues.

Problems with builds on TFS 2010 and resolving dependencies

I have a project that works great on my machine (and production servers).
It's a VS2010 project running C#3.5.
When letting my build server build the solution it can't resolve a couple of my third party dll's.
Error message:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3268: The primary reference
"Third.Party.Assembly,
Version=50.11.2.0, Culture=neutral,
PublicKeyToken=0561a7c6dbd6f0ea,
processorArchitecture=MSIL" could not
be resolved because it has an indirect
dependency on the framework assembly
"Microsoft.VisualBasic.Compatibility,
Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which
could not be resolved in the currently
targeted framework.
".NETFramework,Version=v3.5". To
resolve this problem, either remove
the reference "Third.Party.Assembly,
Version=50.11.2.0, Culture=neutral,
PublicKeyToken=0561a7c6dbd6f0ea,
processorArchitecture=MSIL" or
retarget your application to a
framework version which contains
"Microsoft.VisualBasic.Compatibility,
Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a".
[d:\Builds\3\mySolution.sln]
Everything compiles and runs great on my machine, but the build server seem to struggle.
I think the Third.Party.Assembly is written in VB.net.
Since the assembly is third party I can't remove the reference to "Microsoft.VisualBasic.Compatibility" and since I don't get any warnings on my computer could it really be that I'm running v3.5?
Any suggestions?
/Jimmy
If you put your project on the build server manually will it run? Based on the error message, I would make sure you have the latest .net framework installed on the build server machine and give it another try. If that does not work try installing VS2010 on the build server just to get the builds running until you find out just exactly what assemblies you are missing.
So, I was having this issue also on a VS2005 project that we upconverted... The issue is that MS has never had a 64-bit version of the VisualStudio.Compatability DLL. Our issue was that we were targeting 'Any' CPU and building on a new W2008R2 server so it was using the 64-bit version of the .NET 4.0 Multi-targeting pack.
In the build properties under the 'Process' tab under the '3. Advanced' there is a 'MSBuild Platform'. Change that value to "X86" and it might work... assuming of course you aren't depending on any 64-bit libs...