Topshelf error using NServiceBus

618 views
Skip to first unread message

dpyeates

unread,
Oct 3, 2011, 8:27:48 AM10/3/11
to topshelf-discuss

When running NServicebus, I get the following Topshelf error, can
anyone suggest why I may be getting this?

System: Windows XP SP2 (MSMQ HTTP Support turned on)


NServiceBus.Host.exe!
Topshelf.Extensions.CreateInstanceAndUnwrap<System.__Canon>(System.AppDomain
domain, object[] args) Line 32 + 0x54 bytes C#
NServiceBus.Host.exe!
Topshelf.Internal.FacadeToIsolatedServiceController<NServiceBus.Host.Internal.GenericHost>.Start()
Line 44 + 0x86 bytes C#
NServiceBus.Host.exe!Topshelf.Internal.ServiceCoordinator.Start() Line
48 + 0x85 bytes C#
NServiceBus.Host.exe!Topshelf.Internal.Hosts.ConsoleHost.Run() Line 53
Unknown
NServiceBus.Host.exe!
Topshelf.Internal.Actions.RunAsConsoleAction.Do(Topshelf.Configuration.IRunConfiguration
configuration) Line 32 + 0x8 bytes C#
NServiceBus.Host.exe!
Topshelf.Runner.Host(Topshelf.Configuration.IRunConfiguration
configuration, string[] args) Line 69 + 0xa bytes C#
NServiceBus.Host.exe!NServiceBus.Host.Program.Main(string[] args) Line
105 + 0xb bytes Unknown



Travis Smith

unread,
Oct 3, 2011, 8:38:20 AM10/3/11
to topshelf...@googlegroups.com
Do you have the exception as well, that's just the stack trace? Do you
know what version or NServiceBus or Topshelf you are using? What
version of .NET is this running on, 3.5?

Those items will help greatly, thanks.

-Travis

dpyeates

unread,
Oct 3, 2011, 9:10:39 AM10/3/11
to topshelf-discuss

The exception is [System.Reflection.TargetInvocationException]

Using .NET 3.5 (Visual Studio 2010)

Should be able to post the version of NServiceBus.Host.exe soon (I've
asked the TargetProcess guys what version they deliver and I'm
awaiting reply....)

dpyeates

unread,
Oct 3, 2011, 10:22:25 AM10/3/11
to topshelf-discuss
The version of NServiceBus that is being used is v2.0 'with some
modifications'.

More detail on the exception:

A first chance exception of type 'System.BadImageFormatException'
occurred in mscorlib.dll
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS
\assembly\GAC_MSIL\System.ServiceModel
\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll'
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS
\assembly\GAC_MSIL\System.ServiceProcess\2.0.0.0__b03f5f7f11d50a3a
\System.ServiceProcess.dll'
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS
\assembly\GAC_MSIL\System.Configuration.Install
\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.Install.dll'
A first chance exception of type 'System.BadImageFormatException'
occurred in mscorlib.dll
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\Documents
and Settings\xxxxx\Local Settings\Application Data\assembly
\dl3\009M5MCN.J7V\DBQEJ742.ZPH
\73965c72\0082069e_116dcc01\NServiceBus.Host.EXE', Symbols loaded.
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\Documents
and Settings\xxxxx\Local Settings\Application Data\assembly
\dl3\009M5MCN.J7V\DBQEJ742.ZPH
\ddedc163\0082069e_116dcc01\Microsoft.Practices.ServiceLocation.DLL'
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'Anonymously
Hosted DynamicMethods Assembly'
'NServiceBus.Host.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS
\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a
\System.Drawing.dll'
A first chance exception of type 'System.Security.SecurityException'
occurred in mscorlib.dll
A first chance exception of type 'System.Security.SecurityException'
occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException'
occurred in mscorlib.dll
A first chance exception of type 'System.TypeInitializationException'
occurred in NServiceBus.Host.EXE
A first chance exception of type 'System.TypeInitializationException'
occurred in NServiceBus.Host.EXE
A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in
NServiceBus.Host.exe
An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in
NServiceBus.Host.exe

Additional information: Exception has been thrown by the target of an
invocation.

The program '[4928] NServiceBus.Host.exe: Managed (v2.0.50727)' has
exited with code -532459699 (0xe0434f4d).

René M. Andersen

unread,
Oct 4, 2011, 5:35:17 AM10/4/11
to topshelf...@googlegroups.com
On Windows 7 I have seen this exception if the assembly you are trying to host (or one of its dependencies) is specifically compiled to 32 bits. Instead if all referenced assemblies are compiled to "Any CPU" it should work. Don't know if this is also an issue on Windows XP?

dpyeates

unread,
Oct 4, 2011, 6:06:38 AM10/4/11
to topshelf-discuss
Thanks, I tried with x86, x64 and Any with no luck - I still get the
same error.


Chris Patterson

unread,
Oct 4, 2011, 8:03:16 AM10/4/11
to topshelf...@googlegroups.com
System.Drawing is the assembly? Is this a Windows Forms app or something?

I've only ever used console or class library, so not sure if it's trying to load some drawing code or something that is not legal in a service?

Dru Sellers

unread,
Oct 4, 2011, 4:29:20 PM10/4/11
to topshelf...@googlegroups.com
Not seeing anything obvious. do you have any logs?
-d

Jeremy Lew

unread,
Oct 11, 2011, 8:43:31 AM10/11/11
to topshelf...@googlegroups.com
You almost certainly have a dependency that is compiled to 32-bits.  Are you using any DLLs via COM interop or P/invoke?

Joseph Vano

unread,
Oct 12, 2011, 11:47:53 AM10/12/11
to topshelf...@googlegroups.com
Yep, I agree it is a 32/64 bit issue. I've run into that error before with NServiceBus and it was because we were loading a 3rd party library that was compiled with x86 as the target and our integration assemblies were "Any CPU" on a x64 machine :| Whoops!

If you're unsure what the assemblies are built with, use corflags to check.

I ended up just building my project as x86 specifically so when NServiceBus loaded up it would be in 32bit process.

-
Joey

Moshe Flam

unread,
Aug 16, 2015, 3:11:27 AM8/16/15
to topshelf-discuss
I had a different problem that was solved by updating the NServiceBus package in one of the projects. 
------------------------------------------------------------------
The following was due to the project's NServiceBus not updated...

I tried changing all to 64, did nothing. 
Changed all to 32 bit, and get 
  An unhandled exception of type 'System.InvalidOperationException' occurred in NServiceBus.Host.exe
With the additional information: 
 No endpoint configuration found in scanned assemblies. 
 This usually happens when NServiceBus fails to load your assembly containing IConfigureThisEndpoint. 
 Try specifying the type explicitly in the NServiceBus.Host.exe.config using the appSetting key: EndpointConfigurationType, Scanned path: ...

The problem is that this is an NService-Host project automatically configured by using Nuget.
The only changes I did were to set the persistence (with Nuget of RavenDB, adding a using directive to NServiceBus.Persistence and changing the <Set Persistence Here> to RavenDbPersistence)
and to set the endpointconfig with an endpointclass name so:
   [EndpointName("crb.mpl.BFirstLoanData")]
    public class EndpointConfig : IConfigureThisEndpoint
 
Moved everything back to 64 bits and get the "target invocation" exception 

RavenDB is up and running, and everything in previous projects worked ok. 

== SOLVED!! ==
Then I started listing the versions in my projects.
using: Net: 4.52
I found that the failing project had a different version of NServiceBus  
NServiceBus" version="5.0.0" targetFramework="net452"
instead of 
NServiceBus" version="5.2.4" targetFramework="net452"

I updated and all's well that ends well. 




Reply all
Reply to author
Forward
0 new messages