NServiceBus 5 using AzureStoragePersistence results in "Failed to fetch timeouts from the timeout storage" on machines other then development machine - nservicebus

I try to use Azure Table Storage for the persistence of timeout data and I experience an error on environments other than my local development machine.
My local machine is creating the timeout tables on Azure and is able to poll timeout data successfully. But, if I host the same software on premise on another server it failed to fetch the timeouts. I receive the following error:
2015-02-12 09:43:50,638 [10] WARN NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver - Failed to fetch timeouts from the timeout storage
System.NullReferenceException: Object reference not set to an instance of an object.
at NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver.Poll(Object obj) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Timeout\Hosting\Windows\TimeoutPersisterReceiver.cs:line 88
at System.Threading.Tasks.Task.Execute()
It seems that the TimeoutPersister is null at the point it wants to fetch data from it.
I host NServiceBus using the NServiceBus.Host. My endpoint configuration looks like this:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
public void Customize(BusConfiguration configuration)
{
configuration.UsePersistence<AzureStoragePersistence>();
configuration.EndpointName("MyEndpoint");
configuration.UseTransport<RabbitMQTransport>()
.DisableCallbackReceiver();
configuration.DisableFeature<Sagas>();
configuration.ScaleOut().UseSingleBrokerQueue();();
}
}
And my app.config contains:
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=myrabbitmqserver;virtualhost=myhost;username=me;password=secret" />
</connectionStrings>
<AzureTimeoutPersisterConfig ConnectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=myaccouuntkey;" TimeoutManagerDataTableName="TimeoutManager" TimeoutDataTableName="TimeoutData" />
Does anyone have any idea what I am doing wrong or can anyone point me in the right direction investigating what the problem can be?
Update 1
It seems that the NServiceBus.Azure assembly is not loaded on the other machines. So azure persistence features are not initialized resulting in NullReferenceException when using the TimeoutPersister.
Update 2 After some NServiceBus debugging I noticed that an exception was thrown when extracting the types from the NServiceBus.Azure.dll assembly. It is unable to load the referenced assembly Miscrosoft.Data.Services.Client.dll 5.6.0.0. This assembly is indeed not in the bin folder. The present version is 5.6.3.0. The NServiceBus.Azure NuGet package supports versions >= 5.6.0.0 < 6.0.0.0, but somehow it's still expecting version 5.6.0.0. It still feels weird that it is working on my development machine? Maybe there are some old versions of the Microsoft.Data.Services.Client.dll installed on my machine as part of the Azure SDK, which are found during the assembly loading.
Update 3
I indeed had somewhere at my system the older 5.6.0 version available. Downgrading the Microsoft.Data.xxx packages to version 5.6.0 solved the issue for now. Does anyone have the same issues using 5.6.3 versions and found a solution for that?
Update 4
Since 2015-02-13 a new version of NServiceBus.Azure is released and now it requires Microsoft.Data.Services.Client version 5.6.2.0. I am still not able to use the 5.6.3 version. Adding a assembly binding redirect will not help either.

The binding redirect must be added to the NServiceBus.Host.exe.config instead of the app.config. Pretty annoying because visual studio automatically updates the app.config.
Information from Yves Goeleven:
The reason is that default load behavior of the CLR is at the process level, which includes the host config, once the host is loaded we actively switch over to the appdomain level (using topshelf) from then on it uses the endpoint's config...
But if the CLR needs to resolve the reference prior to the switch to the appdomain, you will have to put the redirect at the host level (and at the endpoint level I guess)

It should work with 5.6.3 version. Try adding assembly bindingRedirect in the following way:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
</dependentAssembly>

Related

Azure Functions: host error has occurred during startup operation Could not load file

I am trying to use Microsoft.AspNetCore.Authentication.Facebook with an Azure functions project. I created a completely clean .net core 3.1 Azure Function project only with the following dependencies:
Microsoft.NET.Sdk.Functions 3.0.7
Microsoft.Azure.Functions.Extensions 1.0.0
Microsoft.AspNetCore.Authentication.Facebook 3.1.5
In the startup file I have the following code:
public override void Configure(IFunctionsHostBuilder builder)
{
facebookOptions.AppId = Environment.GetEnvironmentVariable("Authentication:Facebook:AppId");
facebookOptions.AppSecret = Environment.GetEnvironmentVariable("Authentication:Facebook:AppSecret");
});
When I run the application I get the following error in the console window:
> A host error has occurred during startup operation Could not load file
> or assembly 'Microsoft.AspNetCore.Authentication.Facebook,
> Version=3.1.5.0, Culture=neutral, PublicKeyToken='. The system cannot
> find the file specified.
Any idea what could be wrong?
After I added the user secrets library, debugging stopped working so I spent some time installing different versions of the Azure Functions sdk.
This may only be happening in my project but I decided to share the trial and error summary since this was really time consuming and just in case someone else will be having the same problem.
Microsoft.NET.SDK.Functions version 3.0.5 - 3.0.7
Resulted in the host error has occurred during startup operation Could not load file
Microsoft.NET.SDK.Functions version 3.0.4
Resulted in FunctionsStartup not being called and debugging not triggering
Microsoft.NET.SDK.Functions version 3.0.3
Seems to be working with debugging and no error messages
Version 3.0.3 seems to work so far with debugging and no host error. So I am sticking with this version for now, hopefully it will be resolved in future releases.
Here are the dependencies I have in my solution.
There are two ways to troubleshooting:
Add binding Redirect element in config file.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNetCore.Authentication.Facebook" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="3.1.4" newVersion="3.1.5" />
</dependentAssembly>
</assemblyBinding>
This specifies which version of assembly to use instead of old version. It is not necessarily requires later version be specified in newVersion, earlier version can be provided as well in newVersion.
Update NuGet Package
Update NuGet package in all root project and then in subsequent referred project (if required) where same package is referred.
For more details, you could refer to this article.

How to use signalr v2 beta in asp.net mvc 4

Before v2:
RouteTable.Routes.MapHubs();
In v2, MapHubs does not exist anymore. The wiki says to add a Startup class and a Configuration method and a call to app.MapHubs().
namespace MyAssembly
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//Before v2
//RouteTable.Routes.MapHubs();
app.MapHubs();
}
}
}
But the method is never called, no error occurs, and ... no hub are setup.
I suppose there is some code to add to global.asax.cs
What is the secret ?
Try defining [assembly : OwinStartup(typeof(MyAssembly.Startup))] to see if your Startup class is being picked up.
EDIT: removed lines not relevant.
Solution !
<appSettings>
<add key="owin:AppStartup" value="MyNameSpace.Startup, MyNameSpace" />
</appSettings>
plus update both MVC4 (not to prerelease, but to latest stable version) and SignalR/owin nugets.
plus fix bugs in js client :
if disconnectTimeout=999000 then it is disabled. Must be set server-side with: GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(999);
note: server side can not set a value < 6 (signalr throws an exception if DisconnectTimeout < 6). So use this magic number.
webSockets: set connection.socket = null in sockettransport, otherwise the call to start fails after a (manual) call to stop
serverSentEvents: prevent error caused by a reconnection attempt when the window is unloading
chrome fails with exception if signalr hub url not available (temporarily) : Instead of giving up try the next available protocol / try to reconnect.
I was able to get the 2.0 beta working by
Removing all references to the older version of SignalR, ie nuget uninstall of the library and double checking /bin
Installed SignalR 2.0.0-beta2 via Package Manager Console Install-Package Microsoft.AspNet.SignalR -Pre
Following the steps in the 1.x to 2.0 migration outlined here
And most importantly changing the project config to use Local IIS Web server instead of Visual Studio Developer Server (Cassini).
More info in the question/answer I posted here
In web.config there must be a fully qualified name of the class, e.g.
<appSettings>
<add key="owin:AppStartup" value="**My.Name.Space.Startup**, **AssemblyName**" />
</appSettings>
I had a problem when I put namespace instead of assembly name, but with the fully qualified name it works without any other changes to web.config!
UPDATE: I also followed the steps from the link: http://www.asp.net/vnext/overview/latest/release-notes#TOC13, i.e. removed a NuGet package "Microsoft.AspNet.SignalR.Owin"

Unable to load proxy factory factory exception

I am having this annoying error while running my Nhibernate project. It was running okey and all of a sudden it just start asking for a file in this path "d:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\AbstractBytecodeProvider.cs" and when cancel, it throws an exception saying it says
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
It is become frustrating for me... need help please -:)
Make sure that you have following dlls copied to the output folder and loaded by your process:
NHibernate.ByteCode.Castle.dll
Castle.Core.dll
NHibernate.dll
Iesi.Collections.dll
log4net.dll
And your NHibernate configuration has this line:
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
As an option, you can try to upgrade to latest version of NHibernate - 3.2. They have a built in proxy generator so it should be simpler for you. You will not need these additional dlls. Just remove the config line above if you use NHibernate 3.2.
If for some reasons you can not upgrade to 3.2 you may consider using different byte code providers. NHibernate supports 3 of them out of the box. Try LinFu or Spring:
NHibernate.ByteCode.Castle.ProxyFactoryFactory
NHibernate.ByteCode.LinFu.ProxyFactoryFactory
NHibernate.ByteCode.Spring.ProxyFactoryFactor
Upgrade to the latest version and you will not need an external proxyfactory anymore.

Running NUnit against .Net 4.0 NHibernate over SQLite cannot load SQLite DLL

I know this is a "duplicate", but the answers on all the other posts are not working for me.
My error message is also slightly different.
No matter what I try I cannot get SQLite to to run. I have tried every thing I could find on the net/stackoverflow and every set of SQLite DLLs.
I have tried:
<runtime>
<loadFromRemoteSources enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
I also have tried both safe and unsafe versions of the DLLs.
NUnit.exe will pass the test, but running them with TestDriven.Net in visual studio does not work.
Full stack trace when fluent nhibernate runs the configuration:
SetUp : FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
----> System.Resources.MissingManifestResourceException : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "System.Data.SQLite.SR.resources" was correctly embedded or linked into assembly "System.Data.SQLite" at compile time, or that all the satellite assemblies required are loadable and fully signed.
d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs(232, 0) : FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
C:\inetpub\wwwroot\TrunkB\Company.Tests\BaseNHibernateTest.cs(50, 0) : Company.Tests.BaseSQLiteNHibernateTest.<SetUp>b__1(IInitializationExpression x)
C:\inetpub\wwwroot\TrunkB\Company.Tests\BaseNHibernateTest.cs(36, 0) : Company.Tests.BaseSQLiteNHibernateTest.SetUp()
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Dialect\Schema\AbstractDataBaseSchema.cs(97, 0) : NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords()
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs(47, 0) : NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs(17, 0) : NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs(169, 0) : NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs(1246, 0) : NHibernate.Cfg.Configuration.BuildSessionFactory()
d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs(227, 0) : FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
I am also getting this error now:
Company.Tests.Infrastructure.TruckRepositoryTests.CanLoadTrucksByUserIdFilter:
SetUp : System.BadImageFormatException : Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.
System.BadImageFormatException
This most likely means that you are trying to load a 32-bit assembly into a 64-bit process or vice versa. I imagine that you are running a 64-bit operating system. In this case the program will run as a 64-bit process if Any CPU configuration is selected. One of NUnit and Testdriven.NET might be running as 32-bit and the other 64-bit which will explain why one works and the other doesn't.
Make sure that you are using the correct version of Sqlite (32 bit or 64 bit) when running with a 32/64 bit process.
UPDATE: There is an option for TestDriven.NET for it use 32-bit or 64-bit processes. Go to Tools -> Options -> TestDriven.NET and change ANY CPU tests to use 64-bit instead.
I have this problem using fluent nhibernate and automappings with sqlite, in a .net framework 4 solution, i checked in the new system.data.sqlite site and it's a problem related with the resources inside the library, they already fixed but not it's not a release soon.
The link with the checkin:
Checkin info in system.data.sqlite repository
I downloaded the source code i compiled myself, and it's working now with the automapper in fluent nhibernate, maybe can work for you meanwhile the people of system.data.sqlite relase a new version:
Compiled source code of 1.0.74.0 version with the fix

NServiceBus FullDuplex sample compiled and debugging against .NET 4.0 framework throws exception

I just installed VS2010 RC and launched the FullDuplex sample from NServiceBus 2.0.0.1145 and it ran fine. I then changed the target framework of each project in the solution to ".NET Framework 4", recompiled and launched in the debugger and received the following exception:
System.InvalidOperationException was unhandled
Message=No endpoint configuration found in scanned assemblies. This usually happens when NServiceBus fails to load your assembly contaning IConfigureThisEndpoint. Try specifying the type explicitly in the NServiceBus.Host.exe.config using the appsetting key: EndpointConfigurationTypeScanned path: C:\Development\Personal\ThirdParty\NServiceBus\samples\FullDuplex\MyClient\bin\Debug\
Source=NServiceBus.Host
StackTrace:
at NServiceBus.Host.Program.ValidateEndpoints(IEnumerable`1 endpointConfigurationTypes) in d:\BuildAgent-02\work\672d81652eaca4e1\src\host\NServiceBus.Host\Program.cs:line 189
at NServiceBus.Host.Program.GetEndpointConfigurationType() in d:\BuildAgent-02\work\672d81652eaca4e1\src\host\NServiceBus.Host\Program.cs:line 171
at NServiceBus.Host.Program.Main(String[] args) in d:\BuildAgent-02\work\672d81652eaca4e1\src\host\NServiceBus.Host\Program.cs:line 32
InnerException:
You have to provide the correct supported runtime version in the NServiceBus.Host.exe.config
for example:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="EndpointConfigurationTypeScanned" value="d:\w\ServiceBusTest\"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
The error is actually saying everything :)
The generic host cannot find an endpoint configuration, probably because it fails to dynamically discover and load your .NET 4 assemblies.
You might need to check out the NServiceBus source code and built it against .NET 4 yourself for it to work.
I had this problem and found that my "Start external program" path for NServiceBus.Host.exe was not the folder with my assemblies in, thus meaning it couldn't find any endpoints. In this case, two options are to point to NServiceBus.Host.exe in the bin folder or use menty's answer and add an EndpointConfigurationTypeScanned into the config.
I was never able to get this completely resolved. I first had to convert all of the NSB projects to set the target framework to 4.0. I then upgraded to the latest ilmerge and added the necessary arguments for it to the build script. Next I had to update NAnt and NUnit configuration files to also work with 4.0. I was finally able to get a successful build and ilmerge but now I get an error related to the framework version of TopShelf when executing the upgraded FullDuplex sample using the newly compiled libraries.
I'm assuming I'll have to get newer TopShelf binaries or get the source and build it myself against the 4.0 framework but I haven't been able to look at it in the last week.
Andreas, are there any plans to update the NSB project itself to the 4.0 framework in the near future?