SquishIt icon indicating copy to clipboard operation
SquishIt copied to clipboard

SquishIt.Sass not working

Open AlexCuse opened this issue 9 years ago • 12 comments

Could not load type 'LibSassNet.SassToScssConverter' from assembly 'libsassnet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Both projects reference libsassnet version 1.5

Test project (MVC3) seems to work

MVC 4 project with SquishIt.Sass installed via nuget encounters this exception - package itself doesn't appear to be missing any dependencies.

Both projects targeting .net 4 / AnyCPU, running from visual studio on the same machine (tried with IIS express and without)

Don't see anything missing in the second project's bin directory.

Not willing to go back to iron ruby at this point, and NSass appears to be dead so need to make this work.

AlexCuse avatar Sep 17 '14 00:09 AlexCuse

In the long run probably want to make the 64 bit capable version the default?

My simple test seems to work under the debugger for both x86 and x64 crosses fingers

AlexCuse avatar Sep 17 '14 01:09 AlexCuse

Unfortunately I was faced by two separate issues and started to write about both of them in the other issue #217

For clarification, let me start again!

Using Visual Studio 2013, on Windows 7 I installed (via NuGet) SquishIt.Sass version 0.9.6; this in turn installed libsassnet at version 1.3 (.NET 4.0)

Now the error I was facing was the following

Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Under the advice of @AlexCuse I upgraded libsassnet to version 1.5.0, cleaned and re-compiled my solution, and unfortunately am still met with the same error message. I have tried changing my project from running under ANYCPU to x86 and x64, which unfortunately made no difference at all. My bin directory does in fact contain the LibSass.x86.dll files though as you may see here

image

So I am a bit uncertain on how to proceed. In case it may help, my full error screen is below.

Server Error in '/DocumentManagement/app' Application.

Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'LibSass.x86' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace: 


[BadImageFormatException: Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122

[ConfigurationErrorsException: Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12857578
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +148
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12979668
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12819261

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

Cyberlane avatar Sep 17 '14 13:09 Cyberlane

Updated libsass again, though I'm not sure it is going to help with your issue (seems to happen on CI server as well). We are getting similar errors on the build server, or errors like this for mono:

[16:01:39][Step 2/2] 1) Test Error : SquishIt.Tests.SassTests.CanBundleCssInDebugWithArbitraryScss
[16:01:39][Step 2/2]    System.TypeInitializationException : An exception was thrown by the type initializer for <Module>
[16:01:39][Step 2/2]   ----> <CrtImplementationDetails>.ModuleLoadException : The C++ module failed to load.
[16:01:39][Step 2/2] 
[16:01:39][Step 2/2]   ----> System.MissingMethodException : Method contains unsupported native code
[16:01:39][Step 2/2]   at LibSassNet.SassCompiler.Compile (System.String source, OutputStyle outputStyle, SourceCommentsMode sourceComments, IEnumerable`1 includePaths) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Sass.SassCompiler.CompileSass (System.String input, SassMode mode, System.String location) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Sass.SassPreprocessor.Process (System.String filePath, System.String content) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Framework.Base.BundleBase`1+<PreprocessContent>c__AnonStorey3[SquishIt.Framework.CSS.CSSBundle].<>m__5 (System.String cntnt, IPreprocessor pp) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at System.Linq.Enumerable.Aggregate[IPreprocessor,String] (IEnumerable`1 source, System.String seed, System.Func`3 func) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Framework.Base.BundleBase`1[SquishIt.Framework.CSS.CSSBundle].PreprocessContent (System.String file, SquishIt.Framework.IPreprocessor[] preprocessors, System.String content) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Framework.Base.BundleBase`1[SquishIt.Framework.CSS.CSSBundle].RenderDebug (System.String renderTo, System.String name, IRenderer renderer) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Framework.Base.BundleBase`1[SquishIt.Framework.CSS.CSSBundle].Render (System.String renderTo, System.String key, IRenderer renderer) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Framework.Base.BundleBase`1[SquishIt.Framework.CSS.CSSBundle].Render (System.String renderTo) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at SquishIt.Tests.SassTests.CanBundleCssInDebugWithArbitraryScss () [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
[16:01:39][Step 2/2]   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2] --ModuleLoadException
[16:01:39][Step 2/2]   at <Module>.<CrtImplementationDetails>.ThrowModuleLoadException (System.String errorMessage, System.Exception innerException) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at <Module>.<CrtImplementationDetails>.LanguageSupport.Initialize (<CrtImplementationDetails>.LanguageSupport* ) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at <Module>..cctor () [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2] --MissingMethodException
[16:01:39][Step 2/2]   at (wrapper managed-to-native) <Module>:_getFiberPtrId ()
[16:01:39][Step 2/2]   at <Module>.<CrtImplementationDetails>.LanguageSupport._Initialize (<CrtImplementationDetails>.LanguageSupport* ) [0x00000] in <filename unknown>:0 
[16:01:39][Step 2/2]   at <Module>.<CrtImplementationDetails>.LanguageSupport.Initialize (<CrtImplementationDetails>.LanguageSupport* ) [0x00000] in <filename unknown>:0 

Anyway might be worth a try http://www.nuget.org/packages/SquishIt.Sass/0.9.7-alpha1

AlexCuse avatar Oct 18 '14 04:10 AlexCuse

I too am seeing these issues. I have tried pretty much everything from this thread including installing the 2013 C++ runtime, but I am still getting;

Could not load file or assembly 'LibSass.x86' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This only happens when I run the code in IIS, when running though VS 2012 debug it works perfectly.

Unfortunately I need to be able to run my project in x64 within IIS due to other site resources.

Any thoughts or tips on getting this working?

lakesol avatar Jan 03 '15 12:01 lakesol

/As it stands now, we're going to need to create SquishIt.Sass.x86 and .x64 project, each referencing the appropriate version of libsass-net. I would prefer to get this as a PR from someone who has seen the issue in the wild if possible, so that they can confirm it actually works :)

Holding out some hope for a resolution to this issue: https://github.com/darrenkopp/libsass-net/issues/9 that would eliminate the need. I recently updated to vs2013 so I'm hoping to be able to work on it but since I don't really use SASS I'm not sure how to validate.

AlexCuse avatar Jan 03 '15 17:01 AlexCuse

@lakesol I'm having this problem too... did you find a solution in the end?

aliciam avatar Feb 08 '15 21:02 aliciam

At the moment @aliciam I am just running the site under 32bit until I can find a more permanent solution, so I am afriad not. I expect its will be the .x86 .x64 option described by @AlexCuse above.

lakesol avatar Feb 09 '15 09:02 lakesol

I am also receiving this error, even though I see the required DLL.

Is Squishit intended to run on .NET 4.5 framework? The detailed error makes reference to .NET 4.

And I also notice the error mentions IIS 7, not IIS 8?

mininternet avatar Mar 03 '15 11:03 mininternet

I hade the same issue as described above. So i forked the project: https://github.com/kneeclass/SquishIt/ and made a .x64 version.

Its not the prefect solution as it does not work with.x86.

The problem is that the class ISassCompiler from LibSassNet takes diffrent parameters depending on .x64 or .x86

.x86

return _compiler.Compile(processedInput, OutputStyle.Nested, SourceCommentsMode.None, precision, new[] { location });

.x64

return _compiler.Compile(processedInput, OutputStyle.Nested, false, precision, new[] { location });

A possible and not so beautiful solution would be to call the Compile method using reflection.

EDIT

I now saw that there is a new version of LibSassNet (3.1) out that uses the same method for both x64 and x86. A fix for this should now be possible.

kneeclass avatar Mar 26 '15 10:03 kneeclass

Interesting. I wonder if it'd be possible to reference both DLL's and add some kind of check to the Platform class (SquishIt.Framework) for x86/x64, then use that to delegate to the correct sass compiler? I'm just not sure if .net will let us load both assemblies, or if we'd need to do some kind of dynamic loading at runtime.

I got an update on libsass last week saying that removing the platform-specific builds is in progress, but don't have any idea of timeline. I'm inclined to wait it out but I'm also not really suffering from this problem. If what I described above is workable I'd definitely consider a PR, the only thing I'm certain I don't want to do is put out a platform specific version, unless there is absolutely no other option.

AlexCuse avatar Mar 27 '15 10:03 AlexCuse

Any update on a real fix for this problem? Its been a few months since the last update and just wondering what the latest is?

lakesol avatar May 31 '15 08:05 lakesol

The wheels seem to be turning in libsass-net project to get this done, they have been doing a lot of work to support new sass versions lately though.

I may try to reference both DLLs and hide compiler construction behind a factory that uses the right one for the environment. Not sure if that will work but it's as far as I'm willing to go. There will not be .x86 and .x64 packages for SquishIt.sass - I don't use it and won't be able to test well enough.

If you need it urgently it should be fairly trivial to check out the source, uninstall libsass-net and install libsass-net x64. You'll need to update a reference or two but the compiler should call those out for you.

AlexCuse avatar May 31 '15 12:05 AlexCuse