Posted by dhaynie 2 years 37 weeks ago
Running Windows 7, IIS 7, VS 2008 using VB.NET. Added DA.DLL to the bin directory and attempted to follow the .NET tutorial. The application throws a FileIOPermission error in API.GetTreeFromFile method.
This line:
'mobiForge DeviceAtlas API
Dim hshTree As Hashtable = Api.GetTreeFromFile(Request.PhysicalApplicationPath & "RSS\DeviceAtlas.json")Produces the following error:
System.Security.SecurityException was unhandled by user code
GrantedSet="<PermissionSet class="System.Security.PermissionSet" version="1"> <IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Access="Open"/> <IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Allowed="ApplicationIsolationByUser" UserQuota="512000"/> <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execution"/> <IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Window="SafeTopLevelWindows" Clipboard="OwnClipboard"/> <IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PublicKeyBlob="00240000048000009400000006020000002400005253413100040000010001003BE68021D308920DF3D250D8BD58DA445070955CE2B09C2003990EA3FC57CBDE33D131845035A1B47BAC1DF28412739B2793FA5915B79F9CA12808DA6447DEB1D15E30AA1A343BD4C53E007933856C5A03922E9AE09C5B6A66DC66F99443A60D6C0A24D2E96DC595A9F4E957F64C4684F283715057DA1CF3750B2FA09FC2A2A0" Name="DA" AssemblyVersion="1.3.1.0"/> <IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Url="file:///C:/inetpub/wwwroot/editorial/bin/DA.DLL"/> <IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Zone="Internet"/> <IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" version="1" Level="SafePrinting"/> </PermissionSet> "
Message="Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
PermissionState="<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="C:\inetpub\wwwroot\editorial\RSS\DeviceAtlas.json"/> "
RefusedSet=""
Source="mscorlib"
Url="file:///C:/inetpub/wwwroot/editorial/bin/DA.DLL"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path, Encoding encoding)
at System.IO.File.ReadAllText(String path, Encoding encoding)
at System.IO.File.ReadAllText(String path)
at Mobi.Mtld.DA.Api.GetTreeFromFile(String filename, Boolean reload)
at Mobi.Mtld.DA.Api.GetTreeFromFile(String filename)
at RSS_Mobile.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:At first I thought it was a permissions issue with the .json file but was able to open it directly with a textreader without issue. It appears the error is occuring inside the API method.
Any thoughts or help would be appreciated. Thanks




Posted by dhaynie 2 years ago
Determined that in Windows Vista with VS2008 this is not an issue. Therefore, I assume it is a "feature breaking issue" with either Windows 7 or the version of IIS it comes bundled with.
A workaround for this issue is to read the file into a string from a streamreader object - then use the resultant string to create the hashtable with the .Api.GetTreeFromString method
Dim hshTree As Hashtable = Nothing Dim strPath As String = objContext.Server.MapPath("\data") & "\DeviceAtlas.json" Dim objReader As System.IO.StreamReader = New System.IO.StreamReader(strPath) Dim strTree As String = objReader.ReadToEnd objReader.Close() objReader.Dispose() hshTree = Mobi.Mtld.DA.Api.GetTreeFromString(strTree)