Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windsor WCF integration broken after ASP.NET 4.6 upgrade #84

Closed
Buthrakaur opened this issue Apr 14, 2015 · 13 comments
Closed

Windsor WCF integration broken after ASP.NET 4.6 upgrade #84

Buthrakaur opened this issue Apr 14, 2015 · 13 comments

Comments

@Buthrakaur
Copy link

Hello,
I was trying Visual Studio 2015 CTP and got ASP.NET 4.6 upgrade during the VS installation. I use Windsor WCF integration, which seems to get broken due to this upgrade. I'm injecting Castle.Facilities.WcfIntegration.IWcfClientFactory to my services and use this simple extension method to retrieve the WCF client:

        public static T GetClient<T>(this IWcfClientFactory factory) where T : class
        {
            var componentName = typeof (T).FullName;
            return factory.GetClient<T>(componentName);
        }

The GetClient method throws this exception after the upgrade:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException: WcfClientActivator: could not proxy component XXX ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.RuntimeMethodHandle.GetHashCode()
   at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj)
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.ServiceModel.Dispatcher.OperationSelectorBehavior.MethodInfoOperationSelector..ctor(ContractDescription description, MessageDirection directionThatRequiresClientOpSelection)
   at System.ServiceModel.Dispatcher.OperationSelectorBehavior.System.ServiceModel.Description.IContractBehavior.ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRuntime proxy)
   at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
   at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
   at System.ServiceModel.ChannelFactory.CreateFactory()
   at System.ServiceModel.ChannelFactory.OnOpening()
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ChannelFactory.EnsureOpened()
   at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
   at Castle.Facilities.WcfIntegration.WcfClientActivator.<>c__DisplayClass6.<GetChannelCreator>b__1()
   at Castle.Facilities.WcfIntegration.WcfChannelHolder.CreateChannel()
   at Castle.Facilities.WcfIntegration.WcfChannelHolder..ctor(ChannelCreator channelCreator, IWcfBurden burden, Nullable`1 closeTimeout)
   at Castle.Facilities.WcfIntegration.WcfClientActivator.Instantiate(CreationContext context)
   --- End of inner exception stack trace ---
   at Castle.Facilities.WcfIntegration.WcfClientActivator.Instantiate(CreationContext context)
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
   at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
   at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
   at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(String key, Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.Facilities.WcfIntegration.WcfClientFactorySelector.<>c__DisplayClass2.<SelectComponent>b__1(IKernelInternal k, IReleasePolicy p)
   at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Resolve(IInvocation invocation)
   at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Intercept(IInvocation invocation)
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.IWcfClientFactoryProxy.GetClient[T](String name)

There's obviously some breaking change in ASP.NET 4.6 WCF. I already tried to debug the Windsor source code, bud wasn't able to understand the code enough to be able to figure out where the problem is. Did anyone faced the same problem? Any hints what to try to workaround the problem?

The same error ocurs after recent Windows 10 Windows Update when ASP.NET 4.6 runtime upgrade was delivered.

@mstaessen
Copy link

I got the same issue

@jonorossi
Copy link
Member

I can confirm this is reproducible on .NET Framework 4.6. Running the Windsor unit tests results in 2 failures and 73 errors, many of the errors are this problem but there are also other errors.

Here is stack trace from one of the unit tests: Castle.Facilities.WcfIntegration.Tests.WcfClientFixture.CanAccessDiscoverServiceEndpointMetadata:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException : WcfClientActivator: could not proxy component Castle.Facilities.WcfIntegration.Tests.IOperations
----> System.NullReferenceException : Object reference not set to an instance of an object.
 at System.RuntimeMethodHandle.GetHashCode()
 at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj)
 at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
 at System.ServiceModel.Dispatcher.OperationSelectorBehavior.MethodInfoOperationSelector..ctor(ContractDescription description, MessageDirection directionThatRequiresClientOpSelection)
 at System.ServiceModel.Dispatcher.OperationSelectorBehavior.System.ServiceModel.Description.IContractBehavior.ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRuntime proxy)
 at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
 at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
 at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
 at System.ServiceModel.ChannelFactory.CreateFactory() at System.ServiceModel.ChannelFactory.OnOpening()
 at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ChannelFactory.EnsureOpened()
 at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ChannelFactory`1.CreateChannel()
 at Castle.Facilities.WcfIntegration.AbstractChannelBuilder.DiscoverChannel(DiscoveredEndpointModel model, IChannelBuilderScope scope) in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\Discovery\AbstractChannelBuilder.cs:line 74
 at Castle.Facilities.WcfIntegration.AbstractChannelBuilder`1.Scope.<>c__DisplayClass5.<Castle.Facilities.WcfIntegration.IWcfEndpointVisitor.VisitBindingDiscoveredEndpoint>b__4() in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\AbstractChannelBuilder.Scope.cs:line 137
 at Castle.Facilities.WcfIntegration.WcfClientActivator.<>c__DisplayClass6.<GetChannelCreator>b__1() in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\WcfClientActivator.cs:line 149
 at Castle.Facilities.WcfIntegration.WcfChannelHolder.CreateChannel() in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\Proxy\WcfChannelHolder.cs:line 164
 at Castle.Facilities.WcfIntegration.WcfChannelHolder..ctor(ChannelCreator channelCreator, IWcfBurden burden, Nullable`1 closeTimeout) in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\Proxy\WcfChannelHolder.cs:line 45
 at Castle.Facilities.WcfIntegration.WcfClientActivator.Instantiate(CreationContext context) in c:\src\castle-windsor\src\Castle.Facilities.WcfIntegration\Client\WcfClientActivator.cs:line 77

I don't know much about WCF or our WCF Facility, but attempted to dig into it for a bit. I didn't work out what is causing it, unfortunately Microsoft hasn't released the reference source for 4.6 CTP and the 4.5.2 reference source shows RuntimeMethodHandle.GetHashCode calling ValueType.GetHashCodeOfPtr which is native.

I think someone will need to put together a small example program using just WCF to submit to MSConnect, I couldn't find an existing defect for it but the search is terrible there.

@kkozmic
Copy link
Contributor

kkozmic commented Apr 30, 2015

how about a pull request instead of demands?

On Thu, Apr 30, 2015 at 7:08 PM Matteo Migliore notifications@github.com
wrote:

I've the same problem. Please, fix it ASAP.


Reply to this email directly or view it on GitHub
#84 (comment)
.

@Buthrakaur
Copy link
Author

@kkozmic : I still have it on my todo list, but MS just released .NET 4.6 RC version - I will try it first. They may already fixed this issue.

@matteomigliore
Copy link

@Buthrakaur no, the issue is present also in the RC version.

@matteomigliore
Copy link

Hi @kkozmic :)

Do you have any update? The strange thing is that with another application (LINQPad for example) or a new application that uses .NET 4.0 like our, it works.

I don't understand what can I change to allow a "compatibilty" mode.

LINQPad has this configuration in the app.config:

But I can remove that line and continue to work.

As you can read here.

Have idea how to patch the application? Also on Windows 10 does not work.

Thank you!

@kkozmic
Copy link
Contributor

kkozmic commented Jun 12, 2015

Hi @matteomigliore

No updates. This looks like a bug introduced in WCF 4.6 so it makes sense it would work on older versions of .NET

The best course of action would be to alert Microsoft of this issue's existence and see if they can fix it.

@davkean
Copy link

davkean commented Jun 12, 2015

Thanks for the heads up. We've started looking into this. //cc @roncain @zhenlan

@matteomigliore
Copy link

@kkozmic what I don't understand is why in some applications it works and in other don't. I can create a sample in LINQPad that you can run in a VM with Windows 10 if you can.

Thank you in any case! :)

@polyzois
Copy link

I might add that I only see this Exception if running a 32-bit IIS app-pool. It is not present in a 64-bit IIS app-pool

@Buthrakaur
Copy link
Author

@polyzois good catch. The problem really occurs only in 32-bit process, so the bug isn't that significant these days. I just switched to 64bit version of IISExpress and the problem is gone.

@zhenlan
Copy link

zhenlan commented Jul 2, 2015

Thanks @Buthrakaur for the update and confirm the workaround.

This issue was reported through the Connect feedback to us too. It is not a WCF issue but an issue with 32-bit JIT. I can see the issue has been fixed by the JIT team, so this should work again when Visual Studio 2015 RTM is released.
https://connect.microsoft.com/VisualStudio/feedback/details/1107123/vs-2015-dependency-on-kb3006601-and-wcf

@mstaessen
Copy link

Only 3 failing tests with .NET 4.6 RTM. Guess this issue is resolved then. Thanks @zhenlan for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants