I just ran into this one today while trying to call a WCF service. Doing a search of this on Google/Bing literally yields 3-4 results so I figured I better post something about it in case anyone else comes across it.
First off you might also see it in conjunction with an exception like:
The communication object, System.ServiceModel.ChannelFactory`1[T], cannot be used for communication because it is in the Faulted state.
The above exception isn’t very useful by its self though because in my experience A LOT of WCF issues manifest themselves this way.
I also got an System.IO.FileNotFoundException (“Could not load file or assembly…The system cannot find the file specified.”) which was very confusing because I was just trying to spin up an service contract interface using a ChannelFactory. More on this later…
Some steps I took to resolve the issue:
- Verify that both the client and the server have the same [ServiceContract], [OperationContract](s), [DataContract] and [DataMember] definitions. We are using an assembly that is shared with both the client and server rather than a “service reference” in Visual Studio.
- Ensure that your WCF binding configurations match EXACTLY (to start out with at least) in the <services> section in the service and your <client> section on your client.
- Try calling your service with WCF Test Client and see if it works. This was the annoying part about this issue for me… WCF Test Client worked just fine!
I took a much closer look at the service contract classes and solution and noticed some [CustomAttributes] on some [DataMember] properties in some of the [DataContract]s. I then realized that my client did not have reference to the assembly defining these attributes. I added a reference to the assembly defining these [CustomAttributes] and everything started working… finally! This also explained the FileNotFoundException I was experiencing… whoops!
What I found surprising about this issue is that WCF wasn’t able to create a ChannelFactory simply because I didn’t have reference to an attributes, (not actual [DataMember] property type definitions). It seems that WCF actually does some sort of a serialization on these [CustomAttributes] because it simply didn’t work. This is interesting of course because an attribute can only contain constants so why would it need to have any sort of serialization, hmm… This all makes me wonder a little bit what is going on behind the scenes with attributes on [DataMember] properties.
Hope this helped someone having a similar issue!