System.Data.SQLite and Fluent NHibernate - IDBCommand could not be found - nhibernate

I am trying out Fluent NHibernate 2.12 with System.Data.SQLite (ver 1.0.74.0 with .NET4 x64).
When trying to create my session factory I get the following error (innermost exception):
The IDbCommand and IDbConnection implementation in the assembly
System.Data.SQLite could not be found. Ensure that the assembly
System.Data.SQLite is located in the application directory or in the
Global Assembly Cache. If the assembly is in the GAC, use
element in the application configuration file to
specify the full name of the assembly.
Tried what was already suggested
my app.config looks like this:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
<probing privatePath="Lib\NHibernate;Lib\Castle;Lib\SQLite"></probing>
<qualifyAssembly
partialName="System.Data.SQLite"
fullName="System.Data.SQLite, Version=1.0.74.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</assemblyBinding>
</runtime>
</configuration>
and My private probing path contains the correct files (already checked that)
anyone has a clue?

I just recently set up fluent nhibernate with SQLite for unit tests so here are some tips I can give you.
If you are debugging with Visual Studio 2010 you will need to use SQLite 32 bit sadly. There is a known bug that should be included with the next release of visual studio when you try to include 64 bit assemblies.
Other than that might I suggest you make sure you have included the following entries in your web config.
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
PS found a reference to the bug
http://connect.microsoft.com/VisualStudio/feedback/details/556670/could-not-load-file-or-assembly-error-when-referencing-a-64-bit-assembly

Related

Specify local dll folder upon building VB .NET 2013

When you add a reference to a DLL, you have the option to set the copy local property to True/False. I have looked online and on stackoverflow for a way to specify where that output goes to? I basically would like my assembled exe to be able to reference the dll inside another folder.
My exe would be in the normal root:
/root
but I would want my dll to live inside a folder:
/root/dll_files
for example. Is there any way to achieve this that will work for all dll files?
Keep in mind that I want this to be a dynamic path. I want the dlls to always be in the folder /DLL in reference to the loaded exe
Update
I did try modifying my app.config file to be the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin\DLLs" />
</assemblyBinding>
</runtime>
</configuration>
but the dll's still go into /bin and not /bin/DLLS
Another try
Since I am doing this in vb.net and not C#, I also tried making a main sub:
Public Sub Main()
AppDomain.CurrentDomain.AppendPrivatePath("DLLS")
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1)
End Sub
I then made this my startup module. The module itself launches fine but the dlls still go into the root path, not /DLLS

Import older assembly into .NET 4.0 project [duplicate]

I have a project in which I'd like to use some of the .NET 4.0 features but a core requirement is that I can use the System.Data.SQLite framework which is compiled against 2.X. I see mention of this being possible such as the accepted answer here but I don't see how to actually achieve this.
When I just try and run my 4.0 project while referencing the 2.X assembly I get:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional
configuration information.
What "additional configuration" is necessary?
In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include:
<?xml version="1.0"?><configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup></configuration>
The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work.
Note that this only matters for mixed mode (C++/CLI) assemblies. You can load all managed CLR 2 assemblies without specifying this in app.config.
This forum post on the .NET Framework Developer Center. It might provide some insight.
(Add to the app's config file.)
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Depending on what version of the framework you're targeting, you may want to look here to get the correct string:
http://msdn.microsoft.com/en-us/library/ee517334.aspx
I wasted hours trying to figure out why my release targeting .Net 4.0 client required the full version.
I used this in the end:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"
sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
Once you set the app.config file, visual studio will generate a copy in the bin folder named App.exe.config. Copy this to the application directory during deployment. Sounds obvious but surprisingly a lot of people miss this step. WinForms developers are not used to config files :).
Using 2.0 and 4.0 assemblies together isn't quite straight forward.
The ORDER of the supported framework declarations in app.config actually have an effect on the exception of mixed mode being thrown. If you flip the declaration order you will get mixed mode error. This is the purpose of this answer.
So if you get the error in a Windows Forms app, , try this, mostly Windows Forms apps.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
Or if the project is not Windows Form. In a Web project add this to web.config file.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
Was able to solve the issue by adding "startup" element with "useLegacyV2RuntimeActivationPolicy" attribute set.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
But had to place it as the first child element of configuration tag in App.config for it to take effect.
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
......
....
The above didnt work for me (I am working on a web app) - but this did...
Edit the sgen.exe.config file in the folder (I had to create one first);
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
(There is also one in v7.0 folder, but I didnt need to change that one, I am using VS2012)
The conents of the XML should look like this (same in previous answers)
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup>
</configuration>
If your are working in a web service and the v2.0 assembly is a dependency that has been loaded by WcfSvcHost.exe then you must include
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
in ..\Microsoft Visual Studio 10.0\Common7\IDE\ WcfSvcHost.exe.config file
This way, Visual Studio will be able to send the right information through the loader at runtime.
I ran into this issue when we changed to Visual Studio 2015. None of the above answers worked for us. In the end we got it working by adding the following config file to ALL sgen.exe executables on the machine
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
Particularly in this location, even when we were targeting .NET 4.0:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools
I used this config:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0"/>
<supportedRuntime version="v4.0"/>
</startup>
Worked for me
I had this problem when upgrading to Visual Studio 2015 and none of the solutions posted here made any difference, although the config is right the location for the change is not. I fixed this issue by adding this configuration:
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
To: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config
Then restarted Visual Studio.
I found a way around this after 3-4 hours of googling. I have added the following
<startup selegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
If this doesn't solve your problem then--> In the Project References Right Click on DLL where you getting error --> Select Properties--> Check the Run-time Version --> If it is v2.0.50727 then we know the problem.
The Problem is :- you are having 2.0 Version of respective DLL.
Solution is:- You can delete the respective DLL from the Project references and then download the latest version of DLL's from the corresponding website and add the reference of the latest version DLL reference then it will work.
I was experiencing this same error, and spent forever adding the suggested startup statements to various config files in my solution, attempting to isolate the framework mismatch. Nothing worked. I also added startup information to my XML schemas. That didn't help either. Looking at the actual file that was causing the problem (which would only say it was "moved or deleted") revealed it was actually the License Compiler (LC).
Deleting the offending licenses.licx file seems to have fixed the problem.
I was facing a similar issue while migrating some code from VS 2008 to VS 2010
Making changes to the App.config file resolved the issue for me.
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"
sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
Add following at this location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64
FileName: sgen.exe.config(If you dont find this file, create and add one)
<?xml version ="1.0"?>
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
Doing this resolved the issue
I Use
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
It's works but just before de </configuration> tag otherwise the startup tag doesn't work properly
Also i had this issue with the class library, If any one have the issue with the class library added to your main application. Just add
<startup useLegacyV2RuntimeActivationPolicy="true">
to you main application which would then be picked by the class library.

LinqPad - EntityFramework 4.3.1 - MissingMethodException - Sql Compact

I have my POCO model is seperate dll than my asp.net mvc 3 website.
I created new connection in LinqPad Beta: v4.41.01 selected option for Poco, provided path to custom dll, Chose DbContext, Chose via parameterless constructor.
This did not work, as I am using SqlServer Compact.
Then I created dummy.config file as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="ModelContext"
connectionString="data source=database.sdf"
providerName="system.data.sqlserverce.4.0" />
</connectionStrings>
</configuration>
With this, Test on connection is shown successful. Even, tree on left is also populated. But when I run any query, it throws exception as follows:
Method not found: 'System.Data.Entity.DbSet`1 InventoryModelContext.get_xxx()'.
EDIT: Also, note that this seems to be compilation error!
Any solution or workaround? Am I missing something?
Thanks in advance.
I had this problem as well, it started without any apparent reason - did not change anything in my environment.
I am using EF4.2 Poco, LINQPad 4.42.01
To resolve I started running LINQPad as Administartor, it solved it. I am not sure what has changed that made it break, I have not used LINQPad for a while, so maybe it was some auto-update of LINQPad or something like that.
Update: After reinstalling, for some reason the Administartor trick was not working, a new method I found is query first without specifying a database (at the top right, it says <None>), then i get an error that what I am querying for does not exists in this context, and then I set the database to the correct context, and it works.
Still not sure what is actually causing it.

FluentNhib + System.Data.SQLLite VS2010

I know this question has been posted here before, and I've trawled through as many answers as I could find, but I still can't get the simplest test in the world working.
1) I created my test and ensured it was working in in VS2008 and then opened the the solution in VS2010 (so it's all definlaty working, and all 3.5 code with all the assembly references 2.0/3.0/3.5 references)
2) I added the following config
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="System.Data.SQLite" fullName="System.Data.SQLite, Version=1.0.60.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</assemblyBinding>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
3) I tried the test against both the 1.0.60.0 x86 and 1.0.66.0 x64 SqlLite dlls
4) I tried running the tests in x86 and x64 modes
Still not passing. What have I missed?
(oh, and i'm using SQLite20Driver, and Copy Local is set to true)
The test is a simple Configure()
var cfg = Fluently.Configure(new NHibernate.Cfg.Configuration().Configure())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>()
.Conventions.AddFromAssemblyOf<RequiredPropertyConvention>())
.BuildConfiguration();
var sessionFactory = cfg.BuildSessionFactory();
Error
NHibernate.HibernateException: "The
IDbCommand and IDbConnection
implementation in the assembly
System.Data.SQLite could not be found.
Ensure that the assembly
System.Data.SQLite is located in the
application directory or in the Global
Assembly Cache. If the assembly is in
the GAC, use
element in the application
configuration file to specify the full
name of the assembly."
Stack Trace
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.SQLite20Driver..ctor()
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
NHibernate Config
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">Data Source=nhibernate.db;Version=3</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="query.substitutions">true=1, false=0</property>
</session-factory>
</hibernate-configuration>
If you’re migrating a VS2008 project to 2010, or even starting off a new project chances are that your project references a 3rd party assembly that has not yet been compiled against the .NET 4 framework (yet). To get a V2.0 assembly to run in the .Net 4 runtime you need to enable Mixed Mode, by adding the following to your web.config/app.config:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
useLegacyV2RuntimeActivationPolicy: This tells the runtime to bind assemblies built against older version of .NET against the V4 runtime instead of the runtimes they were built with (force them to use V4)
supportedRuntime: Letting .NEt know that your application supports the V4 runtime and to load your application in the V4 runtime.
For UnitTesting, adding this to the app.config of the project containing the TestFixtures isn’t enough. You need to add this to the app.config of the application actually running the tests, so for NUnit GUI you need to add it to the nunit.exe.config. Furthermore, you’ll need to ensure that you’re using a 2.5.3+ version of NUnit.
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0" />
<supportedRuntime version="v4.0"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
loadFromRemoteSources: CAS has been deprecated in .Net 4 and this line forces partial trust V2 assemblies to be run in full trust.
requiredRuntime: This is because NUnit was built against V2 of the runtime, to load in V4 it needs to be told that it must run in the V4 runtime. (as opposed to only ‘supporting’ it)
If you using a different test runner, such as ReSharper’s test runner, TestDriven.Net or DXCore’s test runner you will need to ensure that you’ve changed their app.config’s to match the above (or wait for .Net 4 builds of them to be released)
Finally, if you’re using 3rd party assemblies that were compiled to target x86 specifically (this will mostly be assemblies that wrap other C/C++ assemblies, like System.Data.SQLite), you either need to grab the 64bit versions of them (as VS2010 by default compiles to x64 when using Any CPU as the Target) or change your Target to x86.

Loading a 3.5 compiled C++/CLI application in .NET 4.0

I'm trying to load a mixed managed application compiled and targeted for Framework 3.5 in the 4.0 CLR.
We have a .config file next to the .exe where I've added this node:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0.21006" />
</startup>
Unfortunately, the app crashes out on startup with a nasty callstack. Can someone in the know confirm that a mixed managed app (.exe is C++/CLI) will not load in 4.0 if it was compiled for 3.5?
I'm watching a Channel9 video about side-by-side CLR hosting, and one of the devs seems to imply that this is the case:
http://channel9.msdn.com/shows/Going+Deep/CLR-4-Side-by-Side-In-Process-What-How-Why/
Thanks!
You need to set useLegacyV2RuntimeActivationPolicy if you want to load a CLR 2 (.NET 3.5) mixed mode assembly in a CLR 4 process:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Without this, you'll get a nasty exception.
You should be able to run 3.5 and 4.0 in the same process. However forcing the app to use 4.0 instead of 3.5 doesn't look possible.
What are you trying to accomplish?