Runtime exception when registering services

Topics: Prism v1
Apr 24, 2009 at 6:33 PM
Hi there,

I'm trying to use the Separated Interface Pattern by separating an interface from its implementation, but got runtime exception when registering a service. I'm using the June 2008 release Prism. Currently I have two different projects, one for the implementation and one for its interface. The implementation project has a reference to the interface project. Below is the code to register the interface and implementation as a service, which resides inside the implementation project. The code is similar to the NewsModule class in the StockTraderRI.

namespace aaa.Services.Broadcast
    public class SeparateInterface : IModule
        private IUnityContainer _container;

        public SeparateInterface(IUnityContainer container)
            _container = container;

        public void Initialize()

        protected void RegisterMyServices()
            _container.RegisterType<IMusic, Music>();

The code runs fine if I put the IMusic interface in the same implementation project. However, when I put them in two separate projects, I can still build without any errors, but got the following runtime exception message:

"Could not load type 'aaa.Services.Broadcast.IMusic' from assembly 'Broadcast, Version=, Culture=neutral, PublicKeyToken=null'."

I stepped through the code, and found that the exception was thrown by RegisterMyServices() inside Initialize().

BTW, I use the same namespace for the two projects.

Any clues what I might be missing?



Apr 24, 2009 at 9:17 PM

Hi Jie,


The code you posted seem to be alright and it is a usual practice to have interfaces in a separated project.


I quickly tried to reproduce your scenario and had no problems registering the service. I tried to reproduce the error and managed to get a similar exception if I set both project's Assembly Name to the same value.

This makes the implementation and interface projects to override the same .dll file, so you will be able to compile fine but at runtime one of the assemblies won't really exist.


If that's your case, just setting one of the project's Assembly Name to a different value will solve the problem. If this does not solve your issue, please provide more information


Hope it helps!


Matias Bonaventura

Apr 24, 2009 at 10:15 PM
Hi Matias,

I checked my dlls, and did have the same assembly name for the two projects. So, I changed one of the assembly names to a different one, and did get rid of the exception. Everything runs smoothly now.

Thanks a lot,