Long Cloud Technologies
"... A Yankee in the Land of the Long White Cloud, Aotearoa ..."

Orchard Source Installation and Problems

Immediate Fixes

orchard permission securitypermission failed

Orchard WARN - Error reading the cached NHibernate configuration Request for the permission of type System.Security.Permissions.SecurityPermission failed config.buildsessionfactory() operation could destabilize the run time

This problem / fix only seems to come up with some development machines, happens on my home machine, but not on my work machine. The full details are here.  The fix is as follows

  1. open the web.config file in the Orchard.Web project
  2. find the <trust level="Medium" originUrl="" /> line (line 48 in the source released for version 1.0)
  3. comment it out.
Visual Studio Hangs when opening Orchard Web Solution Source

Orchard Visual Studio is Busy warning

This problem / fix only seems to come up with SP1 for VS and EcpPageCompletion Extension.

  1. Close Visual Studio if open with Orchard Solution in it.
  2. Reopen Visual Studio, do not load a project
  3. Click menu Tools | Extension Manager…
  4. Find EcpPageCompletion Extension and disable it
       image
  5. Click the restart button and open the Orchard Solution

 

 


Fix Details Section

orchard permission securitypermission failed error details

This following Title & screenshot is from the end of my Orchard: Part Ipost. In that post following the screen shot I make it sound like it worked like it should, but It didn’t. On my home machine it went fashugana. Mind you when I went into work the next day and did the exact same steps on my Work Dev Machine it did work right out of the box, and so this page is my documentation of what steps I took to figure out, and hopefully, fix the issue on my home dev machine.

Site started up, ready for configuration.

image

entered the information and got this

image

Looks like we need to do some debugging, so off to VS and the Debug Menu, finally let’s set up Exceptions to throw up VS even if they are “handled”

image

image

make sure “Thrown” is checked on Common Language Runtime Exceptions and click Ok. Reenter the information on the Orchard page and try it again.

image

So apparently Orchard is trying to open a file in a stream from the “Sites/Default/mappings.bin” and it is getting an empty file, which give us an empty stream, but looking at the errror text in the catch they are expecting this, so let’s let this one go thru. On to the next one.

image

seems this error is possible too looking at the try … catch comments...

BAD Programmer, Bad Bad Programmer

For the record folks, in my opinion (and FXCop and CodeAnalysis opinions as well) the programmers of Orchard are being Bad Programmers in these last two instance. In the two try catch above, please note the bad thing they are doing.  They are expecting it is possible, and allowing for specific errors to happen, and they are catching them to let them fall thru and continue on their way.

            try {
                var formatter = new BinaryFormatter();
                using (var stream = _appDataFolder.OpenFile(pathName)) {

//... snip ...
                    var oldConfig = (Configuration)formatter.Deserialize(stream);

                    return new ConfigurationCache {
                        Hash = oldHash,
                        Configuration = oldConfig
                    };
                }
            }
            catch (Exception e) {
                for (var scan = e; scan != null; scan = scan.InnerException)
                    Logger.Warning("Error reading the cached NHibernate configuration: {0}", scan.Message);
                Logger.Information("A new one will be re-generated.");
                return null;
            }

and this

            try {
                var formatter = new BinaryFormatter();
                using (var stream = _appDataFolder.CreateFile(pathName)) {
                    formatter.Serialize(stream, cache.Hash);
                    formatter.Serialize(stream, cache.Configuration);
                }
            }
            catch (Exception e) {
                //Note: This can happen when multiple processes/AppDomains try to save
                //      the cached configuration at the same time. Only one concurrent
                //      writer will win, and it's harmless for the other ones to fail.
                for (var scan = e; scan != null; scan = scan.InnerException)
                    Logger.Warning("Error storing new NHibernate cache configuration: {0}", scan.Message);
            }

So if it is reasonable for an error to happen and continue on, why do I call them bad programmers?  Because if they are going to allow Specific errors as being normal and ok then they should ONLY capture the errors they are expecting and can handle.  They instead are capturing all errors, even the ones that may NOT BE ok to continue on from.

I strongly believe the catches should be

catch (SerializationException){
    //Note: this can be ignored / can happen when multiple processes....

So the lesson is, if you want to try catch a specific error, only catch the error you want to allow, never use the grab-all general Exception except in extraordinary circumstances.

Now back to our regular programming.

so let’s let it go as well.

image

And this seems to be our problem. this will take some research.

Ok, I’m going to let you see the sausage being made, and me making a VERY stupid error, but first let me put in some SEO stuff so other people who encounter this might find an answer when googling or binging

Orchard WARN - Error reading the cached NHibernate configuration Request for the permission of type System.Security.Permissions.SecurityPermission failed config.buildsessionfactory() operation could destabilize the run time

Ok after a lot of digging turns out the error we need to worry about is the Security error. I KNOW THIS, I’ve encountered this problem MANY TIMES BEFORE. I forgot to mark the zip file of the source code for Orchard as being Safe.

Here I look at the file in file explorer, right mouse it and I have the “unblock” option. If I unzip this file without first clicking that Unblock then dll’s will be given very limited permissions.

image

DOH. So newbies out there, don’t feel bad, I’ve been doing this since 1996 and I still make stupid bonehead mistakes!

Further Historical note: as I sit here typing up this post, twitter has just informed me that it is confirmed that an Official with Japan’s safety agency says that a SECOND probable Meltdown maybe under way at a second reactor at Fukushima Nuclear Reactor. Twitter weren’t wrong.

Well that didn’t work still getting the same error, back to the drawing board. More Research.

Addendum posted on 20 Mar 2011:

So here we are a week later and I have some more information on this bug, and a work around.  Please note I still don’t have a definitive answer as to why it happens only a suspicion and fix to keep things moving along, I may or may not have the time to figure out the underlying problem.

Historical note: as I sit here typing up this post, twitter has just informed me one of the Japanese Nuclear Reactors has stabilised.  Whoo-Hooo, in this case I hope Twitter is correct and that this whole nuclear emergency in Japan is heading towards a final and happy resolution.

So first thing you need to know about .Net Framework 4.0 that I don’t believe has been properly mentioned / blogged about / understood.  That is the underlying security permissions system was completely re-written and it’s core system changed in operation.  In my opinion this is not a small change and should have been talked about A LOT more by Microsoft then it was.  Simply put the whole CAS policy system is being thrown out.  As of 4.0 all the old CAS policy stuff is officially deprecated.  It “still” works… for backward compatibility, but Microsoft is recommending that you DON’T use it any more.

Here are the links to Microsoft’s new security stuff

Security Changes in the .NET Framework 4

Secure Coding Guidelines

I had forgotten about this rather major change in .net framework 4, because I had only learned about it 3 week prior in an unrelated project, and in the end we decided the documentation on the new security system, and more importantly the available documentation and examples were so BAD and non-existent, that we just decided to ignore it and use the deprecated methods.  Hopefully before they get totally retired Microsoft will get around to explaining the new security system to us all for .Net  5.0.

Anyways I did a new search this morning on Google (and to toot my own horn, this very entry was the third one on the list)… but more importantly I followed the first link in Google http://blogs.msdn.com/b/floditt/archive/2009/08/10/request-for-the-permission-of-type-securitypermission-failed.aspx and while it had nothing to do directly with my problem but the part that said

this is probably because the permission set in the config file of the <snip>… </snip> is not configured correctly

reminded me of the changes in the framework, so I went looking in the web.config for the Orchard.Web project and there it was on line 48 <trust level="Medium" originUrl="" /> So I just commented it out and lo and behold Orchard started working on my dev machine at home.

In theory, it SHOULDN’T make any difference, the damn stuff is supposedly backwards compatible and my two dev machines, home and work, are basically configured the same, at least in all the really important issues related to security and running projects in the dev environment.  So obviously we have some deep conflict in the security system model from before 4.0 and 4.0, combined with Orchard source, combined with something special on my dev machine at home.  I may (or may not, time provided) take the time to figure out what the difference is, but for now, I think I will just finish documenting this work around for you, and move on to the next in item in my serious.

Oh and I already know I’ll be back to this page for more installation and compile problems, since I already know what is coming up because I have had a bit of a preview in our other projects: Getting Razor Pages to compile in new modules…


Visual Studio Hangs when opening Orchard Web Solution Source

I had been working on Part II of this series of articles when I had noticed that when opening my Visual Studio it seemed to “hang”. It would lock up for 5 to 10 minutes and I would get the “Visual Studio is busy…” toast notification.  To make things worse this started happening right after the SP1 for VS was released.  Of course I didn’t think this would have any thing to do with Orchard, I thought it was a problem with Visual Studio

In desperation I took a guess that perhaps one of my extensions that I used (and I use quite a few) was causing a problem (mostly because I didn’t want to have to try to uninstall SP1).  So I disabled / uninstalled all my 3rd party tools and extensions just to get the article done.  And the problem went away, rather then take the time to figure out the problem, I went ahead and just left everything disabled and did my work on Part II.  Flash forward to the next day and I slowing start enabling all my extensions and reinstalling my other tools, while working on my normal work (getting the latest of everything) and everyone seems to be hunky dory, so I go on my way. 

Flash forward 3 days and I’m starting work on my Part IIa for this series and low and behold the hanging problem is back.  So I take the couple of hours to do the process of elimination to determine what the problem is.  Turns out it was a very obscure extension provided by Microsoft IT called EcpPageCompletion, that I only added because it came from Microsoft, didn’t even really know what it does, not real well documented.  As long as it is disabled or uninstalled the hang problem goes away.