Scenario 1: Following error is generated from the given sample code: ERROR: at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Environment.get_MachineName() at HelloWorldWebpart.Class1..ctor()
Some Initial Conclusions: Just a vague idea, may be Environment.MachineName does not works with Web application (just meant for Windows Application ). There should be something in web application related stuff. Check Scenario 2.
Scenario 2: Following error is generated from the given sample code: ERROR: at System.Web.HttpServerUtility.get_MachineName() at HelloWorldWebpart.Class1..ctor()
Now, few tests to do before we jump on to root cause analysis:
Few questions, from these tests:
ROOT Cause Analysis: