Use latest version of Npgsql with ServiceStack.OrmLite.PostgreSQL - servicestack

I am using ServiceStack.OrmLite 4.0.9 (with PostgreSQL, which uses Npgsql). It appears that ServiceStack requires a specific version of Npgsql (2.0.11). However, there is a significant bug in Npgsql 2.0.11 (see pull request here and StackOverflow question here). I believe the bug was fixed in Npsql 2.0.12+.
How can I use a later version of Npgsql with ServiceStack.OrmLite.PostgreSQL?
I have tried to simply replace the Npgsql 2.0.11 dll file with the latest version (2.0.14.3, at time of writing), but this causes ServiceStack.OrmLite to throw the following exception:
System.IO.FileLoadException was unhandled by user code
HResult=-2146234304
Message=Could not load file or assembly 'Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=ServiceStack.OrmLite.PostgreSQL
FileName=Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
FusionLog=Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
StackTrace:
at ServiceStack.OrmLite.PostgreSQL.PostgreSQLDialectProvider.CreateConnection(String connectionString, Dictionary`2 options)
at ServiceStack.OrmLite.OrmLiteConfig.ToDbConnection(String dbConnectionStringOrFilePath, IOrmLiteDialectProvider dialectProvider)
at ServiceStack.OrmLite.OrmLiteConnection.get_DbConnection()
at ServiceStack.OrmLite.OrmLiteConnection.Open()
at ServiceStack.OrmLite.OrmLiteConnectionFactory.OpenDbConnection()
at ServiceStack.Service.get_Db()
at XYZ.Post(Abc req) in XYZ.cs:line 45
at lambda_method(Closure , Object , Object )
at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)
ServiceStack.OrmLite.PostgreSQL has probably been compiled against a specific version of Npgsql. Is it possible to use a different version of Npgsql? Or does anyone know when ServiceStack.OrmLite.PostgreSQL will update the version of Npsql it compiles against?

In your config file, add a binding redirect to the version of Npgsql you want to use.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.14.2" newVersion="2.0.14.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Related

Missing assembly binding redirect from StackExchange.Redis 2.0.513 package

I am getting the following exception when trying to use the latest Nuget package StackExchange.Redis in Cloud Service for .Net 4.7
System.InvalidOperationException: The assembly for System.Buffers and System.IO.Pipelines could not be loaded; this usually means a missing assembly binding redirect - try checking this, and adding any that are missing; note that it is not always possible to add this redirects - for example 'azure functions v1'; it looks like you may need to use 'azure functions v2' for that - sorry, but that's out of our control
at Pipelines.Sockets.Unofficial.Helpers.g__Throw|5_0(String msg)
at Pipelines.Sockets.Unofficial.Helpers.AssertDependencies()
at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration, TextWriter log)
at ...
This is coming from a Worker Role in Cloud Service, which is referencing to a class library referencing to this package. Also, I am not able to reproduce this locally. It happens only after deployment to the VM/Cloud Service.
What am I missing?
Add assembly redirect:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="4.0.2.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
Found the details here.

The requested script resource 'Seadragon.Seadragon.Config.js'

i currently updated my site asp.net 3.5 to 4.0. now i have found little problem when my site runs i found this error :
The requested script resource 'Seadragon.Seadragon.Config.js' requires version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' of the ASP.NET AJAX Framework. To use this resource, make sure that the application references version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e'.
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.InvalidOperationException: The requested script resource 'Seadragon.Seadragon.Config.js' requires version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' of the ASP.NET AJAX Framework. To use this resource, make sure that the application references version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e'.
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:
[InvalidOperationException: The requested script resource 'Seadragon.Seadragon.Config.js' requires version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' of the ASP.NET AJAX Framework. To use this resource, make sure that the application references version 'AjaxControlToolkit, Version=4.1.7.1213, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e'.]
System.Web.UI.ScriptReference.GetUrlInternal(ScriptManager scriptManager, Boolean zip) +469796
System.Web.UI.ScriptReference.GetUrl(ScriptManager scriptManager, Boolean zip) +213
System.Web.UI.ScriptManager.RegisterUniqueScripts(List`1 uniqueScripts) +202
System.Web.UI.ScriptManager.RegisterScripts() +444
System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +122
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8872106
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2716
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
You most likely have another version of the toolkit installed. Check your "packages" folder if you are using nuget
I comment the line on web.config
add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"
It works for me.

Configuration exception thrown when ServiceStack RegisterLicense method is called

When invoking this method, Licensing.RegisterLicense(licenseKey);, I get a initialization exception with the following inner error:
Message=Unrecognized configuration section DbProviderFactories. (C:\Actevis\Development\Actevis.Cloud\SqlLiteTestBed\bin\Debug\SqlLiteTestBed.vshost.exe.Config line 16)
Here is the offending config section:
<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>
I have tried adding an appsetting section to the app.config file but the same error still appears. Since the DbProviderFactories are not present in the app.config file I assume that the section is injected by ServiceStack.
I am trying to use ServiceStack.Ormlite.SQLite32. This is the nuget package that was installed. I have copied the license file a few times to make sure that there was not problem there.
Thanks
Thanks for your reply. I was able to figure out what was happening:
When installing the ServiceStack.Ormlite.Sqlite32 package, Entity framework and EntityFramework for SQLServer is also installed. There seems to be an issue when using Sqlite and EntryFramework for Sql Server together. I deleted all the entity framework related DGG's from the project and removed the sections from the app.config file. This has fixed the problem.
The issue is that you're Web.config is invalid and the error gets thrown when first trying to access the Web.config, which is what ServiceStack does when it looks for the servicestack:license app setting.
Note: the <DbProviderFactories> should be declared inside <system.data> tags:
<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>
This was caused by the Web.config.transforms in the dependent System.Data.SQLite.x86 package. This could also be a bug in NuGet's web.config.transform as the rule says to add it under <system.data>...</system.data> but it's being added to the top-level creating an invalid Web.config configuration.
The entire config isn't needed for OrmLite so can be removed. I've also reached out to the SQLite maintainer to notify him about this issue so hopefully will be resolved in future issues.
Whilst I'm looking at making changes to OrmLite's Sqlite packages to embed the dlls and remove the dependency to the Sqlite packages that's causing this error.

HttpResponseMessage unavailable in App_Code folder of VS 2012 project

I am writing a Web API project (MVC architecture). I have a utility class with methods that returns an HttpResponseMessage. If this class is placed in a Utility folder everything works. If I attempt to place the class within the App_Code folder, I receive the message "The type or namespace name 'HttpResponseMessage' found not be found."
An example of a method that this occurs with is provided below. What needs to be done to be able to declare a variable or method as HttpResponseMessage within the App_Code folder?
public HttpResponseMessage GetResponseMessage<T>(T item, MediaTypeFormatter mtFormatter)
{
HttpResponseMessage response = new HttpResponseMessage()
{
Content = new ObjectContent<T>(item, mtFormatter)
};
return response;
}
Files outside of App_Code are compiled when Visual Studio calls the C# compiler and passes it the appropriate referenced assemblies (DLLs) based on the references in the csproj file.
Files inside App_Code are compiled when ASP.NET at runtime calls the C# compiler and passes it the appropriate referenced assemblies (DLLs) based on the reference in the web.config file.
To add a reference to System.Net.Http (the assembly where HttpResponseMessage is located), open your web.config file and merge in this setting:
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>

NService Bus Exception while Handling onStart when Assembly depends on Automapper

We have an assembly using a refernce to the Automapper.dll. Starting the NServiceBus as Subscriber fails on Start with the following message:
Exception when starting endpoint, error has been logged. Reason: Could not load file or assembly 'file:///D:\Main\Src\Core\Core.MessageHandler\bin\Debug\AutoMapper.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
StackTrace:
Server stack trace:
at Magnum.StateMachine.ExceptionActionDictionary`1.HandleException(T stateMachine, Event event, Object parameter, Exception exception)
at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter)
at Magnum.StateMachine.EventActionBase`1.Execute(T instance, Event event, Object parameter)
at Magnum.StateMachine.State`1.RaiseEvent(T instance, BasicEvent`1 eevent, Object value)
at Magnum.StateMachine.StateMachine`1.RaiseEvent(Event raised)
at Topshelf.Internal.ServiceController`1.Start()
at Topshelf.Internal.IsolatedServiceControllerWrapper`1.Start()
at Topshelf.Internal.ServiceControllerProxy.Start()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Topshelf.Internal.ServiceControllerProxy.Start()
at Topshelf.Internal.FacadeToIsolatedServiceController`1.Start()
at Topshelf.Internal.ServiceCoordinator.Start()
at Topshelf.Internal.Hosts.ConsoleHost.Run()
at Topshelf.Internal.Actions.RunAsConsoleAction.Do(IRunConfiguration configuration)
at Topshelf.Runner.Host(IRunConfiguration configuration, String[] args)
at NServiceBus.Host.Program.Main(String[] args)
The file "Automapper.dll" exists! There is no problem in the Config. I checked this removing the dependency to the AutoMapper.dll and it works.
Here is the config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig"
type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig
InputQueue="MyQueue#localhost"
NumberOfWorkerThreads="1"
MaxRetries="10"
ErrorQueue="ErrorQueue#localhost" />
<Logging Threshold="WARN" />
</configuration>
Any idea? Are there known problems with AutoMapper dependencies in NServiceBus?
In your endpoint configuration class (IConfigureThisEndpoint) it's common to implement IWantCustomInitialization as well. As part of that custom initialization you can specify the following:
public void Init()
{
Configure.With(AllAssemblies.Except("Automapper.dll"))
.AutofacBuilder()
.Log4Net(); // etc.
}
The "AllAssemblies.Except()" code instructs the NServiceBus configuration to completely ignore the Automapper assembly.
One other potential issue that may cause the issue is if you're using NServiceBus.Host.exe compiled against the CLR v2.0 (.NET v3.5) while Automapper is compiled against the CLR v4.0 (.NET 4.0). There are several builds of NServiceBus depending upon your CLR version. You may need to try running the CLR v4.0 version of change Automapper to be the .NET 3.5 version (which I believe isn't actively developed).
We had to use a binding redirect to get Autofac + NServiceBus to work. I believe the NServiceBus.ObjectBuilder.Autofac2.dll we referenced used an older version of Autofac than we were using.
app.config:
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" />
<bindingRedirect oldVersion="2.3.2.632" newVersion="2.4.3.700" />
</dependentAssembly>
</assemblyBinding>

Resources