You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When call the same WCF client generated from VS2022 (Add Service Reference) loaded by reflection
through 2 different AssemblyLoadContext the second call causes an InvalidCastException 'Unable to cast object of type 'generatedProxy_2' to type 'ServiceReference3.Service1Soap'.
This is a known issue, you can track the progress/thumbs up this issue in the runtime repo to let them know this is impacting you. I have a potential workaround for you. You need to load the WCF assemblies into the load context. This way DispatchProxy will generate the proxy assembly in a separate AssemblyBuilder instance for your ALC. You can do that with code similar to this:
You probably need to do the same for the type you are using for the binding, eg BasicHttpBinding, or if using a CustomBinding, for the transport binding element.
If you own WcfClient.dll, the least disruptive to consuming code mechanism you can do is to add a module initializer to do this at load time of WcfClient.dll. I put together this code, but I've never tested it. Let me know if this works. Again, you need to add similar code for the assembly containing the binding too.
Thank you very much. I tested the first workaround and it works, actually I don't have ownership on the WcfClient because it'is inside a thirdly part pluggable component. So the best thing I can do is to load the requested Wcf assemblies inside the LC.
Describe the bug
When call the same WCF client generated from VS2022 (Add Service Reference) loaded by reflection
through 2 different AssemblyLoadContext the second call causes an InvalidCastException 'Unable to cast object of type 'generatedProxy_2' to type 'ServiceReference3.Service1Soap'.
To Reproduce
Steps to reproduce the behavior:
TestWcfClient.zip
Check the attached sample project for the full code.
Expected behavior
The WCF client should be called from differents AssemblyLoadContext without exception.
Additional context
Framework: .NET8
VisualStudio 2022 Version 17.11.5
The text was updated successfully, but these errors were encountered: