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.
Related
I use Visual studio 2013 (Windows) to build a small .NET 4.5 application using Npgsql and Entity Framework 6.
On windows it just works fine.
But on Raspbian, the app crash saying it cannot find npgsql provider.
Unhandled Exception:
System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'Npgsql'.
at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00000] in <filename unknown>:0
[...]
On my raspberry pi 2.
I have manually installed Mono v4.0.2
I have copied my app including:
npgsql.dll v2.2.5.0
npgsql.entityframework same version
mono.security v4.0.2
and my app.config contains :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<connectionStrings>
<add name="minitestEntities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=Npgsql;provider connection string="PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;DATABASE=minitest;HOST=10.0.0.1;INTEGRATED SECURITY=True;PASSWORD=azerty;USER ID=theuser"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
So i'm wondering if npgsql librairies are correctly loaded, or a if a reference is missing.
I found no docs on how to use npgsql on recent mono + ARM environment.
Any info about this would be really appreciated.
ok i found the solution in an other discution. In the meanwhile i forgot to note its URL so here the answer :
We have to add manually the provider description into app.config :
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
support="FF"
description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
</DbProviderFactories>
</system.data>
The version and PuclicKeyToken MUST match with npgsql.dll.
To get the public key token, you can run that code :
typeof(Npgsql.NpgsqlFactory).AssemblyQualifiedName
Now i have no idea why this step is not necessary into windows, but a have to do into linux...
I am currently using the Microsoft BCL Async library (here) across a project with a large number of interdependent assemblies all compiled against .NET 4 Full Profile, I have had to use assembly binding redirect in each project to get it to compile (as per issue 2 here).
The problem I now have is that I consume one of these libraries from a C++/CLR DLL project, it does not actually need to use async but I have the following compilation error:
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3268: The primary reference "ImInterface.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "ImInterface.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
I have added the same app.config file that I have used in all of the C# projects but it does not seem to be having any effect in the C++ project. Do I have to place it in a specific directory or perform any other steps to enable the app.config file to be recognised?
The content of my app.config file is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.11.0" newVersion="2.5.11.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.11.0" newVersion="2.5.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Any suggestions are appreciated!
Regards,
Anthony
I had the same problem and as it turned out, <SpecificVersion>True</SpecificVersion> helped.
Before you continue reading, note that the problem seems to only happen when the C++/CLI project is built using the "Visual Studio 2012 - Windows XP (v110_xp)" platform toolset! That is if you don't need to create a DLL which is compatible with WinXP, switch to "Visual Studio 2012 (v110)" instead and you should be fine.
Let me elaborate my scenario:
I have a C++/CLI console application project (ConsoleAppCLI) targeted for WinXP (v110_xp). ConsoleAppCLI references a library (AsyncLib) which has Microsoft.Bcl.Async installed via NuGet:
[ConsoleAppCLI.vcxproj] (C++/CLI, .NET 4.0 v110_xp)
|
|
[AsyncLib.csproj] (C#, .NET 4.0)
|
|
[Microsoft.Bcl.Async] (via NuGet)
I had the exact same problem and the app.config didn't help either, but what did help was the following:
Unload ConsoleAppCli.vcxproj
Edit the vcxproj File directly
Find the reference to the library which has the Async nuget package installed (in my case, a <ProjectReference> to AsyncLib.csproj)
Between <ProjectReference> and </ProjectReference>, ADD THE FOLLOWING: <SpecificVersion>True</SpecificVersion>
Note however, that ConsoleAppCLI was my top-level project in the dependency tree. If you have Assemblies which depend upon the C++/CLI assembly which produced MSB3268, you likewise have to add <SpecificVersion>True</SpecificVersion> to the reference (e.g. if i had an additional C# library which has ConsoleAppCli as dependency, i would have to make the reference to ConsoleAppCli <SpecificVersion>True</SpecificVersion> as well).
This solution is coming from over here, by the way.
The current version of SysCache does not appear to work with NHibernate 3.3. I replaced the NHibernate dlls in my web/bin directory and left the SysCache dll (which works with 3.2) untouched. Now when IIS tries to do a pre-bind it loads the SysCache dll and tries to bind it to NHibernate 3.2.0.4000 and fails.
[FileLoadException: Could not load file or assembly 'NHibernate,
Version=3.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'
or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)] System.RuntimeTypeHandle.GetTypeByName(String name,
Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName,
ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +95
System.RuntimeType.GetType(String typeName, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
+54 System.Type.GetType(String typeName) +50 NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName
name, Boolean throwOnError) +338
NHibernate.Cfg.SettingsFactory.CreateCacheProvider(IDictionary`2
properties) +175
[HibernateException: could not instantiate CacheProvider:
NHibernate.Caches.SysCache.SysCacheProvider,
NHibernate.Caches.SysCache]
NHibernate.Cfg.SettingsFactory.CreateCacheProvider(IDictionary2
properties) +256
NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary2 properties)
+3449 NHibernate.Cfg.Configuration.BuildSettings() +29 NHibernate.Cfg.Configuration.BuildSessionFactory() +44
If I comment out the configuration in the web.config all is well:
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
The download site for NHibernate caches at NHibernate Contrib does not have a download for the latest version.
A different and slightly simpler approach is to override the reference to the 3.2 version of NHibernate in your web.config or app.config with a reference to the desired version 3.3 like so:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4" />
<bindingRedirect newVersion="3.3.0.4000" oldVersion="0.0.0.0-3.3.0.4000" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I've just tried this myself and it works as expected.
The issue probably is that the SysCache Dll is built using NHibernate 3.2.0 and it is not compatible with NHibernate 3.3.0. An easy way around this is to checkout the trunk of the nhibernate config project or the Cache solution only from https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Caches
update the NHibernate reference to use the version that you are using and then rebuild and use the latest cache dlls. Since its a minor upgrade there shouldnt be any code changes required and you should be safe.
Try it and let me know how it goes.
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
I'm trying to generate NHibernate mappings with ActiveRecord. I can create classes from a diagram by targeting ActiveRecord, but whenever I target NHibernate, I get the following error:
Error 1 Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The system cannot find the file specified.
File name: 'NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'
at Castle.ActiveRecord.ActiveRecordStarter.SetUpConfiguration(IConfigurationSource source, Type type, ISessionFactoryHolder holder)
at Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource source, Type[] types)
at Castle.ActiveRecord.ActiveRecordStarter.Initialize(Assembly assembly, IConfigurationSource source)
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].
I am referencing the NHibernate DLL, but it is version 2.0.1.4000 . I added the following into the web.config:
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
<bindingRedirect oldVersion="1.0.0.0-1.2.0.4000" newVersion="2.0.1.4000"/>
</dependentAssembly>
but it is still trying to grab the old NHibernate DLL. Is there something else that must be done to use the new NHibernate?
I ended up scrapping the idea of using newer NHibernate versions and unpacked all the external dlls from the Castle project into the bin directory of the Castle project. After setting that, I was able to generate NHibernate mappings.