1

in the web application with which I'm working we are using Libsass-net for compiling some .scss on runtime, substituting some colour variables in the process.

The weird thing is that locally everything seems to work fine (even if sometimes the error occurs), while when publishing on an azure web server, the compiling works just one or two times fine, after that the sass-compiler.Compile() starts to throw nullreferenceexceptions.

the error trace is the sequent:

System.NullReferenceException: at 
LibSass.Compiler.SassExterns64.sass_compile_file_context (LibSass.NET, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=null) at 
LibSass.Compiler.Context.SassSafeFileContextHandle.CompileInternalContext 
(LibSass.NET, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null) at 
LibSass.Compiler.Context.SassSafeContextHandle.CompileContext (LibSass.NET, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=null)

while the code and the substitution that I'm using is the sequent:

private static CustomImportDelegate _customImportDelegate;

private SassImport[] SassImportDelegate(string currentImport, string parentImport, ISassOptions sassOptions)
    {
            var sassImport = new List<SassImport>();
            var variablesImport = new SassImport();

            if (currentImport.EndsWith("_variables_00_backend"))
            {
                variablesImport.Data = _colorString;
            }
            else
            {
                variablesImport.Path = currentImport;
            }
            sassImport.Add(variablesImport);
            return sassImport.ToArray();

    }

private string GenerateCss(string path)
    {
            _customImportDelegate = SassImportDelegate;
            Telemetrytrace($"path is {path}");
            var sassOptions = new SassOptions
            {
                InputPath = HttpContext.Current.Server.MapPath(path),
                Importers = new[]{ _customImportDelegate },
                IncludeSourceComments = false,
                OutputStyle = SassOutputStyle.Compressed,              
            };

            var sassCompiler = new SassCompiler(sassOptions);
            var sassResult = sassCompiler.Compile();
            return sassResult.Output;   
    }

Is there anyone that had the same problem? any solution out there?

Pouya Samie
  • 3,718
  • 1
  • 21
  • 34
  • According to your description, I have created a test demo on my computer and it works well. I have run my application multiple times. Each time it works well. Could you please tell me what is the version of the Libsass-net?If possible post the sass file content for me to test it again. – Brando Zhang Aug 28 '17 at 09:02
  • Im using libsassnet v 3.3.7 and libsassnet.web 2.3.0 did you run your application in a deployed azure web server? Cause if i run it in a local web application everything goes fine and well, i start to get a bunch of null reference exception after i publish the code online. unfortunately, i can not forward the scss cause i'm talking about thousands of file between external libraries and self written code. – Andrea Marino Aug 29 '17 at 09:15
  • Yes, I have already publish the application to the azure web app. – Brando Zhang Aug 30 '17 at 08:12
  • Hello, so I've tryed to modify the code getting rid of the static variable as suggested from the owner of the library here : https://github.com/sass/libsass-net/issues/60 but my problem is still there. Do you think that might be something related to the settings of the azure web app/server? I'm really puzzled cause after deployment everything seems to work fine, but after recompiling some times I start to get just NullReference Exceptions out of the recompiling process. – Andrea Marino Sep 08 '17 at 08:16

0 Answers0