Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Error running test that requires IsolatedStorage
MatthewSteeples
#1 Posted : Monday, October 12, 2020 8:26:37 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/28/2014(UTC)
Posts: 134
Location: United Kingdom

Thanks: 7 times
Was thanked: 18 time(s) in 16 post(s)
We have some tests that are throwing a SecurityException when trying to save an OpenXml Excel file. It looks like it's trying to use IsolatedStorage (because it's an 8mb file and it saves it to disk instead of in memory). I'm sure I used to know how to solve this kind of problem but I can't work out where to begin with NCrunch!

Has anyone had anything like this before?
Remco
#2 Posted : Monday, October 12, 2020 11:53:20 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Hi, thanks for posting.

NCrunch provides no special handling for IsolatedStorage, so test processes behave the same way as any console application without any user impersonation or configuration. Personally, I have no experience in working with IsolatedStorage, so I can't really advise on how best to proceed here. It may be that some preparation is necessary in your test setup code.
MatthewSteeples
#3 Posted : Tuesday, October 13, 2020 12:13:08 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/28/2014(UTC)
Posts: 134
Location: United Kingdom

Thanks: 7 times
Was thanked: 18 time(s) in 16 post(s)
Hi Remco, does NCrunch load and execute the tests in an AppDomain at all? If so, it's potentially looking like a lack of "evidence" could be the problem. It looks like Isolated Storage uses the identity of the AppDomain to determine where to read and write data, so if this isn't set (as I believe it's optional) then it fails
Remco
#4 Posted : Tuesday, October 13, 2020 3:55:43 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
MatthewSteeples;14988 wrote:
Hi Remco, does NCrunch load and execute the tests in an AppDomain at all? If so, it's potentially looking like a lack of "evidence" could be the problem. It looks like Isolated Storage uses the identity of the AppDomain to determine where to read and write data, so if this isn't set (as I believe it's optional) then it fails


Yes, we do. I wonder if this could be an issue. Here is what we do at the moment:

Code:

var setup = new AppDomainSetup
                 {
                     ApplicationName = "nCrunch.TestRunner_" + externalProcessid,
                     ApplicationBase = appDomainBaseDirectory,
                     ConfigurationFile = configFilePath
                 };

            var evidence = new Evidence();
            evidence.AddHost(new Zone(SecurityZone.MyComputer));
            evidence.AddHost(new Url(typeof(TaskEnvironment).Assembly.CodeBase));

            var appDomain = AppDomain.CreateDomain(
                "nCrunch.TestRunner.AppDomain_" + externalProcessid,
                evidence,
                setup,
                new PermissionSet(PermissionState.Unrestricted)
                );


Do you see any issues here? I wonder if an option would be for you to create a new AppDomain in your test with the parameters that will allow the code to work.
MatthewSteeples
#5 Posted : Tuesday, October 13, 2020 12:13:13 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/28/2014(UTC)
Posts: 134
Location: United Kingdom

Thanks: 7 times
Was thanked: 18 time(s) in 16 post(s)
That looks fine from what I can tell. It might be (because of continuous crunching) that it's run out of space or something like that instead. The line about adding the MyComputer Zone to the evidence is what's recommended. I'll keep digging.
Remco
#6 Posted : Wednesday, October 14, 2020 12:32:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
MatthewSteeples;14990 wrote:
That looks fine from what I can tell. It might be (because of continuous crunching) that it's run out of space or something like that instead. The line about adding the MyComputer Zone to the evidence is what's recommended. I'll keep digging.


Thanks. Sorry that I can't be of more help in this. Let me know if you find anything in the runner that needs adjustment for this.
MatthewSteeples
#7 Posted : Wednesday, October 14, 2020 9:41:11 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/28/2014(UTC)
Posts: 134
Location: United Kingdom

Thanks: 7 times
Was thanked: 18 time(s) in 16 post(s)
Managed to do some digging with this and stepping into framework source / spelunking through ILSpy. On the plus side, this is very easy to reproduce!

https://ledgerscope.shar...oUe1xG5Qpe-3JQ?e=8qjBDC - StackTrace - You can see there's a FileSystemWatcher in here which is what I think is the cause of the problem. It could be (just a guess) that NCrunch is trying to access the IsolatedStorage file without going through the proper procedure
https://ledgerscope.shar...dinpfbEvXTLCaQ?e=gJIyTG - Project with test to reproduce the issue

Happy hunting :)

Let me know if there's anything else I can send.
Remco
#8 Posted : Thursday, October 15, 2020 12:07:48 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Ahh ... now THIS is making sense.

NCrunch tracks the files accessed during a test run using an API hook, so that it knows which tests to mark as impacted if a resource file is changed. Apparently this API hook doesn't work properly when isolated storage is involved.

Switch off the Track file dependencies setting for the test project and the issue will hopefully be gone.
1 user thanked Remco for this useful post.
MatthewSteeples on 10/15/2020(UTC)
MatthewSteeples
#9 Posted : Thursday, October 15, 2020 7:04:17 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/28/2014(UTC)
Posts: 134
Location: United Kingdom

Thanks: 7 times
Was thanked: 18 time(s) in 16 post(s)
Yep, turning off that option fixes our tests. Just to give you a bigger picture of this, it started affecting us because Microsoft's library for generating Excel files starts using Isolated Storage as a temp files location either when the file gets over a certain size or the memory in use by the process reaches a certain limit.

If you end up putting a fix in for it we're happy to test it out for you.

Thanks
Remco
#10 Posted : Thursday, October 15, 2020 7:33:43 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Thanks for confirming. I've scoped a task to look at this issue to see if we can properly fix it. Keeping that setting adjusted is a sensible long term workaround, it's a feature most people never notice anyway and it actually already doesn't work for .NET Core..
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.053 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download