using NetDataContractSerializer throws an exception on client side - wcf

I've tried to move WCF to NetDataContractSerializer using the code in this post:
http://lunaverse.wordpress.com/2007/05/09/remoting-using-wcf-and-nhibernate
and adding this code on the client side:
foreach (OperationDescription desc in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dcsOperationBehavior = desc.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (dcsOperationBehavior != null)
{
int idx = desc.Behaviors.IndexOf(dcsOperationBehavior);
desc.Behaviors.Remove(dcsOperationBehavior);
desc.Behaviors.Insert(idx, new NetDataContractOperationBehavior(desc));
//return true;
}
}
But Eevry time I ivoke my List call, I get this exception:
the formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ListResult. The InnerException message was 'The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[MYPROJ.Framework.Entities.EntityBase, MYPROJ.Framework.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.'. Please see InnerException for more details.
The InnerExcption:
The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[MYPROJ.Framework.Entities.EntityBase, MYPROJ.Framework.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.
The Proxy is generated using svcutils with this flag: /ct:System.Collections.Generic.List`1
so the lists on the other side will not turn into arrays.
The type that the deseriliezer looking is defined in the server. all the entities are derived from this type, but this is not the namespace of the proxy which resides in the client side.
Using Regular default serializer for WCF works fine (there are other problems involving dealing with circular reference the cause me to try a different serializer).
Any Ideas ?
Thanks,
Dani

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/433ba785-581c-4dfa-861a-f22574c1b463
This article says NetDataContract Doesn't support svcutil generated proxy, and you must use a shared dll.

Related

Ektron: synchronization between two servers stopped

We have problem with Ektron synchronization between two servers.
It stopped couple days ago. We tried the “Pause/Resume” button, but that didn’t work.
Do you know where to look for errors and how to troubleshoot this problem?
Please advise.
Updates :
version Ektron 8.6.1
synchronization schedule : daily at 11PM
Restarted services on both machines.
Found error in C:\Program Files (x86)\Ektron\EktronWindowsService40\log\errors
Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The security identifier is not allowed to be the owner of this object.
Source : mscorlib
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void Persist(System.String, System.Runtime.InteropServices.SafeHandle, System.Security.AccessControl.AccessControlSections, System.Object)
HResult : -2146233079
Stack Trace : at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at Ektron.FileSync.Common.FileSyncUtils.ChangePermissions(String filePath, String dirPath)
Stack Trace : at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at Ektron.FileSync.Common.FileSyncUtils.ChangePermissions(String filePath, String dirPath)
Severity: Error
Title:EktronWindowsServices Exception
Application Domain: Ektron.ASM.EktronServices40.exe
Process Id: 1568
Process Name: E:\Program Files (x86)\Ektron\EktronWindowsService40\Ektron.ASM.EktronServices40.exe

ImageResizer AzureReader2 Plugin Nuget Error Out of the Box

I am getting an error when installing the ImageResizer AzureReader2 plugin. This is on a fresh install in an empty web project using Nuget to install the ImageResizer packages.
It is very similar to this issue here, but a binding redirect does not seem to fix the issue. I have also tried updating to 3.0 with the same issue.
Here is the stack :
Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.IO.FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///c:/workspace/CC3.Images/CC3.Images/
LOG: Initial PrivatePath = c:\workspace\CC3.Images\CC3.Images\bin
Calling assembly : ImageResizer.Plugins.AzureReader2, Version=3.4.3.103, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\workspace\CC3.Images\CC3.Images\web.config
LOG: Using host configuration file: C:\Users\steve.westner\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/steve.westner/AppData/Local/Temp/Temporary ASP.NET Files/root/ae2511c3/bb7d3a9/Microsoft.WindowsAzure.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Users/steve.westner/AppData/Local/Temp/Temporary ASP.NET Files/root/ae2511c3/bb7d3a9/Microsoft.WindowsAzure.Configuration/Microsoft.WindowsAzure.Configuration.DLL.
LOG: Attempting download of new URL file:///c:/workspace/CC3.Images/CC3.Images/bin/Microsoft.WindowsAzure.Configuration.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
ImageResizer.Plugins.AzureReader2.AzureVirtualPathProvider..ctor(String blobStorageConnection) +0
ImageResizer.Plugins.AzureReader2.AzureReader2Plugin.Install(Config c) +379
ImageResizer.Configuration.PluginConfig.add_plugin_by_name(String name, NameValueCollection args) +275
ImageResizer.Configuration.PluginConfig.loadPluginsInternal() +402
ImageResizer.Configuration.PluginConfig.LoadPlugins() +102
ImageResizer.Configuration.Config..ctor(ResizerSection config) +546
ImageResizer.Configuration.Config.get_Current() +115
ImageResizer.InterceptModule.get_conf() +36
ImageResizer.InterceptModule.System.Web.IHttpModule.Init(HttpApplication context) +250
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9931880
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248
I resolved this issue by moving to ImageResizer version 4.0 stack, which at this time is in pre-release and was not showing in the package manager console.
The following command installed everything needed :
Install-Package ImageResizer.Plugins.AzureReader2 -Pre

How can I force Unity App Block to load new Object instances in WCF?

I am using Unity Application Block to load my dependancies, a problem I am having is when all my dependancies are loaded it is behaving abnormally.
I have a service that takes a business interface using constructor injection, and that business interface takes a repository interface as constructor injection. The problem I have is when I load user details from the database the field values are always the same (even after I manually change them in the DB). Therefore I think it is because it is using the same instance EntityFramework context instance for each time the service is opened.
The only way I can get Entity Framework to load the correct details is to recycle IIS.
Is there a way I can force Unity to create new object instances for its dependancies and force them to be dispose when the WCF request has completed?
I have tried using the transient lifetime manager but this is not curing the problem.
Code:
public class UserService : IUserService
{
private IUserAdmin _UserBusiness { get; set; }
public UserService()
{
}
[InjectionConstructor]
public UserService(IUserAdmin userBusiness)
: this()
{
this._UserBusiness = userBusiness;
}
}
public class UserAdmin : BusinessBase, IUserAdmin
{
private IRepository<DBUserAccount> _UserRepository { get; set; }
[InjectionConstructor]
public UserAdmin(IRepository<DBUserAccount> userRepository)
{
this._UserRepository = userRepository;
}
}
public class GenericRepository<T> : IDisposable, IRepository<T> where T : class, new()
{
private Entities _Context;
private ObjectSet<T> _ObjectSet;
public GenericRepository()
{
this._Context = new Entities();
this._ObjectSet = this._Context.CreateObjectSet<T>();
}
}
Unity Config:
<register type="Services.Contracts.IUserService, Server.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"
mapTo="Services.Implementations.UserService, Server.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be">
<lifetime type="transient"/>
</register>
<register type="Server.Business.Users.IUserAdmin, Server.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"
mapTo="Server.Business.Users.UserAdmin, Server.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be">
<lifetime type="transient"/>
</register>
<register type="Server.DataLogic.IRepository`1[[Server.DataModels.DBUserAccount, Server.DataModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be]], Server.DataLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"
mapTo="Server.DataLogic.GenericRepository`1[[Server.DataModels.DBUserAccount, Server.DataModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be]], Server.DataLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be">
<lifetime type="transient"/>
</register>
It seems that you haven't implemented a unit of work pattern in your application. The Unity configuration looks correct but seems that your changes aren't being committed. Look at this blog post from the EntityFramework team to see how you would implement one. You should also ensure the your implementation properly disposes of the EntityFramework context when committing the unit of work as discussed in this SO question and answer

Can't Able to get Instance of ExceptionManager

I am using Enterprise Library 5.0 in Silverlight using mvvm-light Framework.
When I'm going to getInstace of ExceptionManager Class like:
var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
exceptionManager.HandleException(E.Error, "Policy");
I Got this type of error Message
Activation error occured while trying to get instance of type ExceptionManager, key ""
Resolution of the dependency failed, type = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager", name = "(none)"
Exception occurred while: while resolving.Exception is: InvalidOperationException - The type TraceListener cannot be constructed. You must configure the container to supply this value
-----------------------------------------------
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManagerImpl,ExceptionManager.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager, (none))
Resolving parameter "exceptionPolicies" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManagerImpl(System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] exceptionPolicies, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IDefaultExceptionHandlingInstrumentationProvider instrumentationProvider)
Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl,Policy
Resolving parameter "policyEntries" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl(System.String policyName, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] policyEntries)
Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry,Policy.All Exceptions
Resolving parameter "handlers" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry(System.Type exceptionType, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PostHandlingAction postHandlingAction, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] handlers, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Instrumentation.IExceptionHandlingInstrumentationProvider instrumentationProvider)
Resolving Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,Policy.All Exceptions.Logging Exception Handler (mapped from Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler, Policy.All Exceptions.Logging Exception Handler)
Resolving parameter "writer" of constructor Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler(System.String logCategory, System.Int32 eventId, Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceEventType severity, System.String title, System.Int32 priority, System.Type formatterType, Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter writer)
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (none))
Resolving parameter "structureHolder" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder structureHolder, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider, Microsoft.Practices.EnterpriseLibrary.Logging.IAsyncTracingErrorReporter asyncTracingErrorReporter)
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder, (none))
Resolving parameter "traceSources" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder(System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] traceSourceNames, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation)
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,General
Resolving parameter "traceListeners" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String name, System.Collections.Generic.IEnumerable`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight, Version=5.0.505.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceListeners, Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.SourceLevels level, System.Boolean autoFlush, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider)
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.Diagnostics.TraceListener,Flat File Trace Listener
At Line of
var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
My Configuration File is:
<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:el="http://schemas.microsoft.com/practices/2011/entlib">
<el:ExceptionHandlingSettings x:Key="exceptionHandling">
<el:ExceptionHandlingSettings.ExceptionPolicies>
<el:ExceptionPolicyData Name="LogPolicy">
<el:ExceptionPolicyData.ExceptionTypes>
<el:ExceptionTypeData Name="All Exceptions" TypeName="System.Exception, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<el:ExceptionTypeData.ExceptionHandlers>
<el:LoggingExceptionHandlerData LogCategory="General" FormatterTypeName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Silverlight, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Priority="-1" Name="Logging Exception Handler" />
</el:ExceptionTypeData.ExceptionHandlers>
</el:ExceptionTypeData>
</el:ExceptionPolicyData.ExceptionTypes>
</el:ExceptionPolicyData>
</el:ExceptionHandlingSettings.ExceptionPolicies>
</el:ExceptionHandlingSettings>
<el:LoggingSettings DefaultCategory="General" x:Key="loggingConfiguration">
<el:LoggingSettings.TraceSources>
<el:TraceSourceData Name="General">
<el:TraceSourceData.TraceListeners>
<el:TraceListenerReferenceData Name="Flat File Trace Listener" />
</el:TraceSourceData.TraceListeners>
</el:TraceSourceData>
</el:LoggingSettings.TraceSources>
<el:LoggingSettings.SpecialTraceSources>
<el:SpecialTraceSourcesData>
<el:SpecialTraceSourcesData.AllEventsTraceSource>
<el:TraceSourceData Name="All Events" />
</el:SpecialTraceSourcesData.AllEventsTraceSource>
<el:SpecialTraceSourcesData.NotProcessedTraceSource>
<el:TraceSourceData Name="Unprocessed Category" />
</el:SpecialTraceSourcesData.NotProcessedTraceSource>
<el:SpecialTraceSourcesData.ErrorsTraceSource>
<el:TraceSourceData Name="Logging Errors & Warnings">
<el:TraceSourceData.TraceListeners>
<el:TraceListenerReferenceData Name="Flat File Trace Listener" />
</el:TraceSourceData.TraceListeners>
</el:TraceSourceData>
</el:SpecialTraceSourcesData.ErrorsTraceSource>
</el:SpecialTraceSourcesData>
</el:LoggingSettings.SpecialTraceSources>
</el:LoggingSettings>
</ResourceDictionary>
It looks like your configuration is referencing a trace listener called "Flat File Trace Listener" but there is no trace listener defined by that name.
Also, you should be aware that the Enterprise Library Silverlight Logging Application Block does not support a Flat File Trace Listener. Valid actions are:
Logging to a remote WCF Service.
Logging to isolated storage.
Logging to an event.

Unity unable to correctly resolve WCF InstanceContext implementation

I'm attempting to set up the client for a duplex WCF service via Unity 2.0. To do so, I want to insert an implementation of my CallbackContract - IUpdateClient - into an InstanceContext, which is then inserted into my service proxy, in this case a subclass of DuplexClientBase<IUpdateService> called UpdateProxy.
The problem I encounter is, when attempting to use the Proxy as stored in my Unity container to subscribe the client to updates from the service, I receive the following exception:
The InstanceContext provided to the
ChannelFactory contains a UserObject
that does not implement the
CallbackContractType
'..Services..ServiceContracts.IUpdateClient'.
I am accessing the proxy like so:
_container.Resolve<IUpdateService>("updateServiceImpl").Subscribe();
Given my Unity config:
<!-- Interface to implementation mappings -->
<register type="RepositoryInterface" mapTo="Repository" name="repositoryImpl">
<constructor>
<param name="proxy" dependencyName="proxyImpl"/>
</constructor>
</register>
<!-- Here's the bit that doesn't seem to be resolving as expected -->
<register type="UpdateClientInterface" mapTo="UpdateClient" name="updateClientImpl">
<lifetime type="singleton"/>
<constructor>
<param name="repository" dependencyName="repositoryImpl"/>
</constructor>
</register>
<register type="System.ServiceModel.InstanceContext, System.ServiceModel,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="instanceContext">
<constructor>
<param name="implementation" dependencyName="updateClientImpl"/>
</constructor>
</register>
<!-- This is the type I'm resolving with the above _container.Resolve() statement -->
<register type="UpdateServiceInterface" mapTo="UpdateService" name="updateServiceImpl">
<constructor>
<param name="callbackInstance" dependencyName="instanceContext"/>
</constructor>
</register>
<register type="ProxyInterface" mapTo="Proxy" name="proxyImpl">
<constructor>
<param name="configurationName">
<value value="ServiceEndpointFromAppConfig"/>
</param>
</constructor>
</register>
I would expect that when I resolve the UpdateService class, seen here:
public class UpdateProxy : DuplexClientBase<IUpdateService>, IUpdateService
{
public UpdateProxy(InstanceContext callbackInstance)
: base(callbackInstance) {}
public void Subscribe() {}
[...]
}
That the Unity container instantiates an InstanceContext (registered as "instanceContext" in config) and, when doing that, it must instantiate the type registered as "updateClientImpl" - which does, in fact, implement IUpdateClient - and pass that into the InstanceContext's constructor as its implementation parameter.
Nonetheless, I receive the error as above.
In Summary (aka "the tl;dr version"): When the Unity container resolves an InstanceContext, it doesn't seem to create its implementation correctly. I don't know if this is an error in configuration, or if I'm fundamentally misunderstanding how the Unity container resolves a set of dependent types. Any guidance on this would be helpful.
The issue you're running into is because you registered the InstanceContext with a name. However, the UpdateProxy type isn't registered at all. So what's happening is the container will attempt to resolve InstanceContext using the default, unnamed registration.
However, since there is no default registration, the defaults kick in and it looks like it is choosing a different constructor.
The fix would be to either register UpdateProxy and set that registration to use the named registration for InstanceContext or to remove the name from the registration for InstanceContext.