NHibernate 3.3 and SysCache - nhibernate

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.

Related

Specflow - GenerateFeatureFileCodeBehindTask has failed unexpectedly

I have a problem with SpecFlow. We are using Azure Devops and when I build solution on my local machine it works perfectly but during Azure Devops build I am getting following error:
[error]C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\specflow.tools.msbuild.generation\3.1.86\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): Error MSB4018: The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified.
File name: 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType)
at TechTalk.SpecFlow.Generator.Plugins.GeneratorPluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor)
at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.LoadPlugins(ObjectContainer container, GeneratorPluginEvents generatorPluginEvents, UnitTestProviderConfiguration unitTestProviderConfiguration, IEnumerable`1 generatorPlugins)
at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings, IEnumerable`1 generatorPluginInfos, IObjectContainer parentObjectContainer)
at SpecFlow.Tools.MsBuild.Generation.WrappedGeneratorContainerBuilder.BuildGeneratorContainer(SpecFlowConfigurationHolder specFlowConfigurationHolder, ProjectSettings projectSettings, IReadOnlyCollection`1 generatorPluginInfos, IObjectContainer rootObjectContainer)
at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTaskExecutor.Execute()
at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="SpecFlow" Version="3.1.86" />
<PackageReference Include="SpecFlow.MsTest" Version="3.1.86" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.1.86" />
I have tried using it with nUnit, MsTest, xUnit and it alway fails.
Target framework: .NET Core 3.1.
Build agent: vs2019-win2019
We've encountered same problem, after longer digging I found that there is an issue created for this in their git repo https://github.com/SpecFlowOSS/SpecFlow/issues/1912.
Quoting from git issue:
MSBuild 16.5 has a new assembly loading approach for tasks that may have side effects. (which has been an ask for years, but it behaves a bit differently when loading dependencies)
You can try to set MSBUILDSINGLELOADCONTEXT=1 (env var) to get the old behavior.
Try to set it in your build pipeline as:
variables:
...
MSBUILDSINGLELOADCONTEXT: '1'
...
This helped in our case.
EDIT:
This issue seems to be fixed in newer version of SpecFlow (3.3.15+).
Had the same problem for SpecFlow 3.4.8 after migration from SpecFlow 2.
Since After version SpecFlow 3.3.30 don’t need to add the SpecFlow.Tools.MSBuild.Generation package anymore
so i have removed SpecFlow.Tools.MSBuild.Generation package, however issue still there.
After that i have added specflow.json to test project and issue gone
Had the same problem, turned out that it was version issues between .net core SDK and Specflow. We downgraded .net core sdk to 3.1.102 and that helped
Uninstalling and reinstalling specflow and SpecFlow.Tools.MsBuild.Generation worked for me
I had this issue after specflow runner installation. Removing it solved the problem
The error message says:
Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified.
File name: 'TechTalk.SpecFlow, Version=3.1.0.0
You have SpecFlow v3.1.86 installed. I would expect it to be loading TechTalk.SpecFlow 3.1.86, which matches the NuGet package version.
Either:
Uninstall and reinstall the SpecFlow package using the Package Manager Console:
uninstall-package SpecFlow -force -project NameOfYourTestProject
install-package SpecFlow -version 3.1.86 -project NameOfYourTestProject
Edit the .csproj file for your test project and ensure the <Reference> element importing the DLL file is pointing to the correct file
<Reference Include="TechTalk.SpecFlow, Version=3.0.0.0, Culture=neutral, PublicKeyToken=..., processorArchitecture=MSIL">
<HintPath>..\packages\SpecFlow.3.1.86\lib\FRAMEWORK_VERSION\TechTalk.SpecFlow.dll</HintPath>
</Reference>
Note: Replace FRAMEWORK_VERSION with net45, netstandard2.0, etc depending on the .NET framework version of your test project.
You can always open Windows File Explorer and browse to the DLL file in order to discover the correct path.
Last ditch effort, try restoring NuGet packages manually from the command line, assuming you have NuGet.exe available in your %PATH% (See https://learn.microsoft.com/en-us/nuget/install-nuget-client-tools for more info)
nuget restore Path/To/YourSolution.sln
So glad this post exists. The tests would run on my machine but not in azure pipeline.
I upgraded to the latest specflow and SpecFlow.NUnit and this solved the issue ... updated from 3.7.13 to 3.9.8. I don't understand but glad it worked.

dll versions displayed in visual studio .Net not reflecting the referenced dll file/product versions

I have a console app c# project that depends on NHibernate 3.3.2 and ShapArch.NHibernate 2.0.4.628 which has been compiled with NHibernate 3.3.1 (as far as I know - I might be wrong, but when I created a 2.0.4 SharpArch project it downloaded NH 3.3.1 via Nuget ).
Why does Visual Studio show NHibernate as being version 3.3.1.4000 when the referenced dll is 3.3.2.4000? The Specific Version property is set to false for all references. And the version for SharpArch appears in VS 2.0.0.0 instead of 2.0.4 which is the file/product version.
In the app config I have:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.4000" newVersion="3.3.2.4000" />
</dependentAssembly>
</assemblyBinding>
</runtime>
The app fails to load with:
System.IO.FileLoadException was unhandled
Message=Could not load file or assembly 'NHibernate, Version=3.3.2.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)
Source=MyApp.ResourcesGenerator
FileName=NHibernate, Version=3.3.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
FusionLog=""
StackTrace:
at MyApp.ResourcesGenerator.Program.InitializeNHibernateSession()
at SharpArch.NHibernate.NHibernateInitializer.InitializeNHibernateOnce(Action initMethod) in d:\Builds\SharpArch2\Solutions\SharpArch.NHibernate\NHibernateInitializer.cs:line 54
at MyApp.ResourcesGenerator.Program.Initialize() in C:\projects\tc\Trunk\Source_LibsUpgrade\Applications\PerformanceManagement\MyApp.ResourcesGenerator\Program.cs:line 149
at MyApp.ResourcesGenerator.Program.Main(String[] args) in C:\projects\tc\Trunk\Source_LibsUpgrade\Applications\PerformanceManagement\MyApp.ResourcesGenerator\Program.cs:line 31
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileLoadException
Message=Could not load file or assembly 'NHibernate, Version=3.3.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)
FileName=NHibernate, Version=3.3.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
I am not even sure why it's trying to load 3.3.0.4000 when sharp architecture has been compiled with 3.3.1.
NHibernate 3.3.2.GA has a file version of 3.3.2.4000 but the assembly version is still 3.3.1.4000. This was done to allow an upgrade of NHibernate without needing binding redirects. All future minor version upgrades of NHibernate will also follow this pattern.
So the solution for you is just to remove the binding redirect.
The confusing part here is that the Windows Explorer only shows the file and product versions but Visual Studio only shows the assembly version.

Entry point was not found exception

I have installed vs2012 (11.0.50727.1),
I opened a new MVC4 with .NET 4.5 solution,
i create a simple HomeController and as I've wanted to start it locally, i have received this very strange error:
How can resolve it? What is this error and why it's happens???
Thank you in advance, for any of your help.
Server Error in '/' Application.
Entry point was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.EntryPointNotFoundException: Entry point was not found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[EntryPointNotFoundException: Entry point was not found.]
System.Web.Mvc.IDependencyResolver.GetService(Type serviceType) +0
System.Web.Mvc.DependencyResolverExtensions.GetService(IDependencyResolver resolver) +56
System.Web.Mvc.SingleServiceResolver`1.GetValueFromResolver() +44
System.Lazy`1.CreateValue() +180
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
System.Lazy`1.get_Value() +10749357
System.Web.Mvc.SingleServiceResolver`1.get_Current() +15
System.Web.Mvc.MvcRouteHandler.GetSessionStateBehavior(RequestContext requestContext) +121
System.Web.Mvc.MvcRouteHandler.GetHttpHandler(RequestContext requestContext) +33
System.Web.Mvc.MvcRouteHandler.System.Web.Routing.IRouteHandler.GetHttpHandler(RequestContext requestContext) +10
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9709656
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
I have converted a project from MVC3+.NET4 to MVC4+.NET4.5 and I receive the exception Entry point was not found when invoking a controller's action.
My solution was to insert an assembly binding redirect inside web.config to point at MVC 4 assemblies:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I don't know the exact cause of the problem, maybe some third party library that still references MVC3.
The same error appears when you switch you project from MVC3 to MVC4 and forget to change System.Web.WebPages.Razor, Version=1.0.0.0 to System.Web.WebPages.Razor, Version=2.0.0.0 in the web.config.
Old post but if you encounter it prior to the mvc woes (System.Mvc.dll update e.g x.0.0.1) you could check the bindingRedirect tag(4.0.0.0 -> 4.0.0.1)
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
</dependentAssembly>
If you are catching this error in WebAPI Controller - you need fix binding
version of System.Web.Http
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
you should also check that all of the projects in your solutions reference the latest versions of the dll's, and that there are no inconsistent versions being used by different sub-projects.
despite running nuget uninstall, install and update I found the tests project was referencing an old version of the system.net.http
If you are using .net 4.5 and adding a binder to ModelBinders.Binders collection from a .net 4.0 library you will also get such error.
Do you have something like this in your Global.asax.cs?
private static void InitializeDependencyInjectionContainer(HttpConfiguration config)
{
container = new UnityContainer();
container.RegisterType<Site.Web.Data.IDatabaseFactory, Site.Web.Data.DatabaseFactory>();
container.RegisterType<Site.Web.Data.Interfaces.IUnitOfWork, Site.Web.Data.UnitOfWork>();
container.RegisterType<Site.Web.Data.Interfaces.IUserRepository, Site.Web.Data.Repositories.UserRepository>();
container.RegisterType<Site.Web.Data.Interfaces.ISiteRepository, Site.Web.Data.Repositories.SiteRepository>();
From the stack trace you posted System.Web.Mvc.IDependencyResolver.GetService(Type serviceType) +0 would suggest one (or more) of your dependencies don't resolve.
You could try commenting one or more of them out and try to narrow down which one is failing to resolve.
Old post but just to add for anyone looking
This seems like a catch all error. I got it when my web.config used an external section and that section was excluded from the Visual Studio project, i.e. using this
<sessionState configSource="SystemWeb.config" />
Try this.. in visual studio go to Package Administrator Console and type:
update-package
I faced this problem and solved it by
1. uninstall-Package Microsoft.AspNet.Mvc (I need to uninstall something else before I can uninstall AspNet.MVC successfully)
2. Install-Package Microsoft.AspNet.Mvc -Version 4.0.20710
3. Rebuild and deploy
Not MVC specific in my case, but had just started getting this error:
Server Error in '/' Application.
Entry point was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.EntryPointNotFoundException: Entry point was not found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[EntryPointNotFoundException: Entry point was not found.]
...
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8008
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
What caused that was that I had published to the webserver folder from Visual Studio and selected to Precompile the app (using a .NET 4.5 project), with allow precompiled site to be updateable setting btw.
Probably my issue was that the site is running at .NET 4.0 on IIS, whereas the precompiled version placed in bin folder during the publish action was for 4.5. When I removed the "bin" folder from the website it run fine again.
Just update "System.Web.Mvc" with "nuget"

NHibernate under SharePoint 2010

I am having trouble getting NHibernate up and running under SharePoint 2010.
My config code works as I have an integration test project running fine.
The problem is to do with gac assemblies and NHibernate references resulting in this error:
[FileNotFoundException: Could not load file or assembly 'NHibernate.ByteCode.Castle' or one of its dependencies. The system cannot find the file specified.]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
System.Reflection.Assembly.Load(String assemblyString) +35
NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError) +641
NHibernate.Bytecode.AbstractBytecodeProvider.SetProxyFactoryFactory(String typeName) +67
[UnableToLoadProxyFactoryFactoryException: Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.
Possible causes are:
- The NHibernate.Bytecode provider assembly was not deployed.
- The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.
Solution:
Confirm that your deployment folder contains one of the following assemblies:
NHibernate.ByteCode.LinFu.dll
NHibernate.ByteCode.Castle.dll]
NHibernate.Bytecode.AbstractBytecodeProvider.SetProxyFactoryFactory(String typeName) +336
NHibernate.Cfg.Configuration.ConfigureProxyFactoryFactory() +179
NHibernate.Cfg.Configuration.BuildSessionFactory() +23
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +50
FYI, NHibernate.ByteCode.Castle is registered in the gac. I also have these two item in web.config:
<compilation batch="false" debug="true">
<assemblies>
<add assembly="NHibernate.ByteCode.Castle, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4" />
....
&
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="NHibernate.ByteCode.Castle, Version=3.1.0.4000, Culture=neutral" fullName="NHibernate.ByteCode.Castle, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4" />
...
Any clues as to the extra wiring required?
The "or one of its dependencies" remark might be worth further investigation. Get Dependency Walker and check whether NHibernate.ByteCode.Castle.dll depends on anything else, and if it does, whether it's in the GAC or not.
this was the key bit, not specifying culture or version in the partialName:
<qualifyAssembly partialName="NHibernate.ByteCode.Castle" fullName="NHibernate.ByteCode.Castle, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4" />
did the trick

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.