jetheredge / SquishIt

Lets you *easily* bundle some css and javascript! Check out the Google group if you have questions!
http://groups.google.com/group/squishit
MIT License
459 stars 119 forks source link

.net 4 #316

Open AlexCuse opened 9 years ago

AlexCuse commented 9 years ago

Seems our mutex usage is problematic running under .net 4

ex:

Test 'SquishIt.Tests.StylePreprocessorPipelineTests.WithPreprocessor_Uses_Instance_Preprocessors' failed: System.MethodAccessException : Attempt by security transparent method 'SquishIt.Framework.Utilities.FilePathMutexProvider.CreateSharableMutex(System.String)' to access security critical method 'System.Threading.Mutex..ctor(Boolean, System.String, Boolean ByRef, System.Security.AccessControl.MutexSecurity)' failed.

Assembly 'SquishIt.Framework, Version=0.9.8.1, Culture=neutral, PublicKeyToken=null' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
    Utilities\FilePathMutexProvider.cs(96,0): at SquishIt.Framework.Utilities.FilePathMutexProvider.CreateSharableMutex(String name)
    Utilities\FilePathMutexProvider.cs(76,0): at SquishIt.Framework.Utilities.FilePathMutexProvider.CreateSharableMutexForPath(String normalizedPath)
    Utilities\FilePathMutexProvider.cs(47,0): at SquishIt.Framework.Utilities.FilePathMutexProvider.GetMutexForPath(String path)
    Utilities\CriticalRenderingSection.cs(18,0): at SquishIt.Framework.Utilities.CriticalRenderingSection..ctor(String path)
    Base\BundleBase.Rendering.Internals.cs(251,0): at SquishIt.Framework.Base.BundleBase`1.RenderRelease(String key, String renderTo, IRenderer renderer)
    Base\BundleBase.Rendering.Internals.cs(155,0): at SquishIt.Framework.Base.BundleBase`1.Render(String renderTo, String key, IRenderer renderer)
    StylePreprocessorPipelineTests.cs(122,0): at SquishIt.Tests.StylePreprocessorPipelineTests.WithPreprocessor_Uses_Instance_Preprocessors()
AlexCuse commented 9 years ago

http://stackoverflow.com/a/23885583

AlexCuse commented 8 years ago

This is kinda crappy but I guess it works if I understand right.

        public CriticalRenderingSection(string path)
        {
            try
            {
                mutex = MutexProvider.GetMutexForPath(path);
                mutex.WaitOne();
            }
            catch
            {
                mutex = null;
            }
        }

Medium trust in general is going to be more painful now, some of the directory manipulation stuff needed for preprocessing fails when invoked as well. Core functionality should still work OK.