I rarely post about the issues I am experiencing in this blog. This is mostly because most of the solutions are already there in the web. So, what pushed me to publish this post, is extremely rare scenario, that as I suspect might not be covered somewhere else.
In our testing automation framework we make extensive use of virtual machines. Most of control messages are passed using vSphere API (VIM API). To my dismay, I discovered that some of previously working code using this API ceased working properly, namely it start throwing exception during connection attempt:
System.Configuration.ConfigurationErrorsException: Insufficient permissions for setting the configuration section 'defaultProxy'. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
...
at Microsoft.Web.Services3.WebServicesClientProtocol.GetReaderForMessage(SoapClientMessage message, Int32 bufferSize)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Vim25Api.VimService.RetrieveServiceContent(ManagedObjectReference _this)
...
After digging up previous changes in related code configuration, I found that the problem was the following section added to the app.config of the project:
<system.net>
<defaultProxy>
<proxy autoDetect="False"/>
</defaultProxy>
</system.net>
Apparently, few months ago I added this configuration to prevent delays in WCF connection between framework modules. The connection between lack of proxy detection and the authentication is vague, but not totally non existent – as the reality shows. So, if you found this article while looking for help regarding that exception in the title, you might want to check your proxy settings.
Hope that helps.