TypeLoadException: Type 'generatedProxy_5' from assembly 'ProxyBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
A colleague shared with me the following strange error message he got when he tried to use a .NET Standard library I created:
An unhandled exception occurred while processing the request.
TypeLoadException: Type 'generatedProxy_5' from assembly 'ProxyBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
· TypeLoadException: Type 'generatedProxy_5' from assembly 'ProxyBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
o System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
o System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
o System.Reflection.DispatchProxyGenerator+ProxyBuilder.CreateType()
o System.Reflection.DispatchProxyGenerator.GenerateProxyType(Type baseType, Type interfaceType)
o System.Reflection.DispatchProxyGenerator.GetProxyType(Type baseType, Type interfaceType)
o System.Reflection.DispatchProxyGenerator.CreateProxyInstance(Type baseType, Type interfaceType)
o System.Reflection.DispatchProxy.Create<T, TProxy>()
o System.ServiceModel.Channels.ServiceChannelProxy.CreateProxy<TChannel>(MessageDirection direction, ServiceChannel serviceChannel)
o System.ServiceModel.Channels.ServiceChannelFactory.CreateProxy<TChannel>(MessageDirection direction, ServiceChannel serviceChannel)
o System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel<TChannel>(EndpointAddress address, Uri via)
o System.ServiceModel.ChannelFactory<TChannel>.CreateChannel(EndpointAddress address, Uri via)
o System.ServiceModel.ChannelFactory<TChannel>.CreateChannel()
o System.ServiceModel.ClientBase<TChannel>.CreateChannel()
o System.ServiceModel.ClientBase<TChannel>.CreateChannelInternal()
o System.ServiceModel.ClientBase<TChannel>.get_Channel()
o IRD3Service.IRD3ServiceClient.MbCoreGetIdentificerendeEenheidAsync(int idIe) in Reference.cs
Inside this library I’m doing a WCF call to get some data from a backend service. WCF internally generates a proxy for the WCF client through the ProxyBuilder and it is this ProxyBuilder that started to complain…
The problem seems to be that I generated all my proxy types as internal(which should be a good thing). But the ProxyBuilder does not agree with me.
Some research (thanks Google!) brought me to the following possible solutions:
- Change all proxy types from internal to public
- Add an InternalsVisibleToAttribute(“ProxyBuilder”) to the library
I tried the second approach and it worked! Up to the next problem…