How to setup Binding redirect with Nunit's gui runner? - nunit

I am trying to run my unit tests with nHibernate 3 and fluentnHibernate, To do this I need to setup a assembly binding redirect so fluentnHibernate will work with the new version of nHibernate. I have tried to update my test project's app.config however the testdriven.net runner and the nunit gui runner don't seem to read these settings.
below is my test.dll's app.config.
<configuration>
<configSections>
<!-- Others sections -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<connectionStrings>
<add name="Test" connectionString="Data Source=SQL2008, 1080;Initial Catalog=TestCOM;Integrated Security=True"/>
</connectionStrings>
<log4net>
<appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
<file value="Logs.txt"/>
<appendToFile value="true"/>
<maximumFileSize value="100KB"/>
<rollingStyle value="Size"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="GeneralLog"/>
</logger>
</log4net>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0.30319" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly
partialName="System.Data.SqlServerCe"
fullName="System.Data.SqlServerCe,
Version=3.5.1.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
<dependentAssembly>
<assemblyIdentity name="NHibernate"
publicKeyToken="AA95F207798DFDB4"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.1001"
newVersion="3.0.0.1001"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I am getting the following error:
TestCase 'FieldGuideTests.Service.SchemaFacts.Can_Build_SQL_Schema'
failed: System.IO.FileLoadException : Could not load file or assembly 'NHibernate, Version=2.1.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)
at FieldGuideService.SessionFactoryManagers.SQL_SessionFactoryManager.CreateSessionFactory()

Related

Npgsql EntityFramework, error - value argument incorrect in ConnectionString - Paramter name: app

I'm hoping someone can give me an idea as to why I'm getting the above error within my project. I'll try to include as must information as possible.
From my packages.config:
<packages>
<package id="AutoMapper" version="4.2.1" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="log4net" version="2.0.8" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="Npgsql" version="2.2.7" targetFramework="net45" />
<package id="Npgsql.EntityFramework" version="2.2.7" targetFramework="net45" />
</packages>
The project is database driven and as such I have been able to connect to my PostgreSQL database and created the *.edmx file(s) plus generated the respective controllers, models and repository file(s) for each table. Through this process I have the auto generated connection string ("aaa" == sub name):
<add name="aaaPGS" connectionString="metadata=res://*/aaaPGS.csdl|res://*/aaaPGS.ssdl|res://*/aaaPGS.msl;provider=Npgsql;provider connection string="port=5432;timeout=15;pooling=True;minpoolsize=1;maxpoolsize=20;commandtimeout=20;compatible=2.2.3.0;ApplicationName=aaa;host=aaaVM;database=aaaDB;user id=aaaid;password=aaapwd;App=EntityFramework"" providerName="System.Data.EntityClient" />
In my App.config file I have the following settings:
<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>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
</runtime
As you can see I have a SQL connection also, this connection works fine however when I try to perform the same query through postgreSQL I get the following error:
"value argument incorrect in ConnectionString - Paramter name: app"
I don't believe the connection string is in error as it was auto generated but may be I'm wrong? Is there an "app" setting I'm missing? Is this error a by product of something else? Any help much appreciated.

EF 6 Code First from database model generating error

Installed VS 2015 latest update and all packages are up-to-date. Then I encountered following error almost every time while re-generating data model using code first from database (I used T4 with a bit customization). Never had this error before. Sometimes I can solve this error by restarting VS 2015 or rebooting my workstation, but not always. Anybody has the same issue. Thanks for your help.
An error occurred generating the Code First model. The error occurred generating the contents of DbCtx.cs.
System.InvalidOperationException: Compiling transformation: The type ‘DbModel’ exists in both ‘EntityFramework, Version=4.2.0.0, Colture=neutral, PublicKeyToken=b77a5c561934e089’ and 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at Microsoft.Data.Entity.Design.CodeGeneration.CustomGenerator.ProcessTemplate()
at Microsoft.Data.Entity.Design.CodeGeneration.CustomGenerator.Generate(DbModel model, String codeNamespace, String contextClassName, String connectionStringName)
at Microsoft.Data.Entity.Design.CodeGeneration.CodeFirstModelGenerator.d__3.MoveNext()
======== Here is my web.config file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<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>
<appSettings>
.......
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="myDB" connectionString="data source=local DB;initial catalog=test;user id=user;password=pwd;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
It seems you add both Entity Framework V.6 and V.4 as reference to your project. remove one of them.

Database connection fails with Local IIS but works with IIS Express

I am working on MVC with Entity Framework. My solution is able to connect to database, SQL Server 2008 R2, when I run my solution with IIS Express, as soon as I change to Local IIS, it starts throwing error: An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code.
While Error Message was: The underlying provider failed on Open.
I am able to browse through pages which do not require database connection.
Following is the web.config file
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="EmployeeContext" connectionString="server=.; Database=Database1; integrated security=SSPI"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>

unable to create entity framework database in class library

I have a class library. within this project I have a folder named 'models' with a few class models. I have all the references I need.
app.config:
<?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>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="DefaultConnection2" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MDD;AttachDbFilename=|DataDirectory|\MDD.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
After running update-database it throws the following error:
A file activation error occurred. The physical file name '\MDD.mdf'
may be incorrect. Diagnose and correct additional errors, and retry
the operation. CREATE DATABASE failed. Some file names listed could
not be created. Check related errors.
solved.
the app.config does not suppose to have <connectionStrings>. the Web.config do.
then in the MyDbContext.cs:
public MyDbContext():base("connectionString"){}

Log4Net in Resharper Unit Test Runner but not in NUnit Unit Runner

I'm using the latest 5.x ReSharper plugin with NUnit 2.5.10. When using Log4Net to log some events for testing purposes the results show up in the ReSharper test window, but do not show up when using NUnit's console unit runner (run as part of our build processes). I've tried giving NUnit a .config file in the same location as the .nunit configuration file with the LogLevelThreshold set to DEBUG, but it still won't log the actual test information to either the output file or the text window in NUnit's GUI. I'm a bit stumped at this point, is there a way to get the two in sync in what's being displayed by test output? Thanks!
Configs in question:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestCaseBuilder" type="System.Configuration.NameValueSectionHandler"/>
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="DefaultLogThreshold" value="DEBUG" />
</TestRunner>
</NUnit>
</configuration>
And other config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
<!--<appender-ref ref="DebugAppender" />-->
</root>
<logger name="NHibernate">
<level value="INFO" />
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG" />
</logger>
</log4net>
</configuration>
Thanks in advance for any help.