Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WE (current stable version and nightly) often crash VS 2013 upon building project #871

Closed
chadwells opened this issue Apr 7, 2014 · 37 comments

Comments

@chadwells
Copy link

I have an existing project that builds fine with WE disabled, but when I enable WE and then build the project, VS crashes about 75% of the time. Event log shows the following error:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.IO._Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
at System.IO.StreamReader..ctor(System.String, System.Text.Encoding, Boolean, Int32, Boolean)
at System.IO.File.InternalReadAllText(System.String, System.Text.Encoding, Boolean)
at System.IO.File.ReadAllText(System.String)
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.RaiseReady()
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.FileTouched(System.Object, System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.OnChanged(System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32, System.String)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32, UInt32, System.Threading.NativeOverlapped
)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped)

@chadwells
Copy link
Author

Some more info that may or may not help. If I run VS as Administrator, then build my project, no crash. But then I build again, and I get a crash. if I debug devenv.exe during this. I get:

System.IO.IOException was unhandled
Message: An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file 'C:\Dev\KlipschWeb\KlipschWeb.Selector\js\app\models\Endpoint.js' because it is being used by another process.

Endpoint.js is the compiled version of Endpoint.ts. Endpoint.ts (and some other source files) were open in the editor. So, trying again, I closed all open files and I can't seem to get VS to crash like it had been. So then I just opened a different TS file (main.ts) and I edited the file with a blank line, and when I tried to build, I get the same sort of trace.

I'm going to see if I get similar problems with a new TS project.

@am11
Copy link
Contributor

am11 commented Apr 7, 2014

And please test it with the latest nightly build of WE andVS 2013 Update 2 RC.

@chadwells
Copy link
Author

Sorry… I should have specified. I'm already using VS 2013 Update 2 RC and the latest nightly (from 4/6/2014)

I have just tested with a new TS project and I can't duplicate the crash I was getting on my existing project.
I suspected maybe there was a file permissions issue between WE, VS, and Git, but I so far can't prove that to be the case.

@chadwells
Copy link
Author

Update: Just tested with the latest Nightly version of WE 2013 and the issue persists.

@ShaneGarza
Copy link

I am having similar issue with WE Update 2 RC (2.0.2) where VS crashes when saving a JavaScript file that is included in a bundle. I can stop VS from crashing by commenting out the file references in the bundle before editing and saving the script files. The event viewer points to a WinIOError and using procmon there is a sharing violation that occurs on the bundle output file. If minify is set to true the sharing violation usually occurs when trying to create the min file.

I have noticed that the frequency that VS crashes seems to be related to the number of files in the bundle. 2-3 files takes about 5-10 edits and saves to force a crash. More than 5 files in the bundle and it will crash in 1 or 2 save attempts.

Bundle output file name is app.js:
app.js SHARING VIOLATION Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Open No Recall, Attributes: n/a, ShareMode: Read, AllocationSize: 0

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.IO._Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
at System.IO.File.InternalWriteAllText(System.String, System.String, System.Text.Encoding, Boolean)
at System.IO.File.WriteAllText(System.String, System.String, System.Text.Encoding)
at MadsKristensen.EditorExtensions.BundleFilesMenu.WriteBundleFile(System.String, System.Xml.XmlDocument)
at MadsKristensen.EditorExtensions.BundleFilesMenu.UpdateBundle(System.String, Boolean)
at MadsKristensen.EditorExtensions.BundleFilesMenu.UpdateBundles(System.String, Boolean)
at MadsKristensen.EditorExtensions.BundleFilesMenu.b__0(System.Object, System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.OnChanged(System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32, System.String)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32, UInt32, System.Threading.NativeOverlapped
)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped)

@tomvdk
Copy link

tomvdk commented Apr 10, 2014

Same problem here. Also using VS 2013 Update 2 and WE RC2.
Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException

@chadwells
Copy link
Author

I previously wasn't able to reproduce the issue with a new project if the project was created on a network share, but if I create a new project on my local drive (where my existing project that was having the issue is located), I can reproduce it.

The steps I took to reproduce:

  1. Create new Project using HTML Application with TypeScript template, targeting .NET 4.5.1. Save the project somewhere on your local drive (for my example, I have C:\Dev). Do have it create directory for solution, Don't add to source control.
  2. After the new solution loads, just build the solution. The build should succeed. (this step may not even be 100% necessary)
  3. in app.ts, just add a new line somewhere, and save the file.
  4. This is when the VS crash happens for me in this case. VS will then restart itself.

The event log has this error (appears to be exact same error previously mentioned):
Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.IO._Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
at System.IO.StreamReader..ctor(System.String, System.Text.Encoding, Boolean, Int32, Boolean)
at System.IO.File.InternalReadAllText(System.String, System.Text.Encoding, Boolean)
at System.IO.File.ReadAllText(System.String)
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.RaiseReady()
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.FileTouched(System.Object, System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.OnChanged(System.IO.FileSystemEventArgs)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32, System.String)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32, UInt32, System.Threading.NativeOverlapped
)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped)

Immediately after that event in the Application event log, there is this Application Error, if it helps at all:
Faulting application name: devenv.exe, version: 12.0.30324.0, time stamp: 0x532f84b4
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17031, time stamp: 0x53088860
Exception code: 0xe0434352
Fault offset: 0x00014dbd
Faulting process id: 0xcc
Faulting application start time: 0x01cf54c20c3b608e
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
Faulting module path: C:\WINDOWS\SYSTEM32\KERNELBASE.dll
Report Id: eb0ca7da-c0b5-11e3-bf5b-001c42ef5806
Faulting package full name:
Faulting package-relative application ID:

@am11
Copy link
Contributor

am11 commented Apr 10, 2014

Changing this code to:

using(var reader = File.OpenText(TargetFilePath))
{
    OnCompilationReady(new CompilerResultEventArgs(
                CompilerResultFactory.GenerateResult(
                    sourceFileName: SourceFilePath,
                    targetFileName: TargetFilePath,
                    isSuccess: true,
                    result: reader.ReadToEnd(),
                    errors: null
                )));
}

might solve this issue.

Can you guys try it, if you have VS-SDK installed?

Fork the project, clone it via VS, open solution, make the aforementioned changes, set EditorExtensions as a startup project, start (will launch experimental instance of VS), open the culprit project and test.

If it fixes the issue, please send the PR.

@SLaks
Copy link
Collaborator

SLaks commented Apr 10, 2014

You would also need to pass a more relaxed FileMode and FileShare

@chadwells
Copy link
Author

I've forked/cloned the project, and upon making the change you suggested and trying to modify then build my test project in the experimental VS instance, I get this IO exception:

System.IO.IOException was unhandled
HResult=-2147024864
Message=The process cannot access the file 'C:\Dev\testerror\testerror\app.js' because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamReader..ctor(String path)
at System.IO.File.OpenText(String path)
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.RaiseReady() in c:\Dev\WebEssentials2013\EditorExtensions\TypeScript\Compilers\TypeScriptCompilationNotifier.cs:line 162
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.FileTouched(Object sender, FileSystemEventArgs e) in c:\Dev\WebEssentials2013\EditorExtensions\TypeScript\Compilers\TypeScriptCompilationNotifier.cs:line 137
at System.IO.FileSystemWatcher.OnChanged(FileSystemEventArgs e)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32 action, String name)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
InnerException:

I tried with my main project that first alerted me to the issue just to be sure and get the same thing.

@am11
Copy link
Contributor

am11 commented Apr 10, 2014

Can you try with:

using(FileStream fileStream = File.Open(TargetFilePath, FileMode.Open, FileAccess.Read))
using(StreamReader reader = new StreamReader(fileStream))
{
    ...
}

OR

using(FileStream fileStream = new FileStream(TargetFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using(StreamReader reader = new StreamReader(fileStream))
{
    ...
}

@chadwells
Copy link
Author

I've tried both of those suggestions (even after re-forking the latest repository) and I get the same error :-(

@am11
Copy link
Contributor

am11 commented Apr 11, 2014

We might need to use policy to ensure that no file reads and writes are missed. For example.

@SLaks any suggestions. Here is a related exception reporter for WriteAllText(_).

@SLaks
Copy link
Collaborator

SLaks commented Apr 11, 2014

We can prevent it from crashing on async exceptions by properly terminating every async action with .DontWait().
This means no async voids, and that all calls to async Task methods should be awaited or DontWaited.

All of these errors should be avoidable with FileShare.ReadWrite, unless the other code has locked it exclusively.

If that happens often, we can make an async wrapper method that catches the exception and waits a few hundred milliseconds, then tries again.

@am11
Copy link
Contributor

am11 commented Apr 11, 2014

That's a great idea. I was hoping if file watcher provides some event for this..

We can probably make a job queue service for read/write I/O operations and then serve all the related calls made by WE to this service. All those calls must be await'ed and would provide retry count to the service method. Going by search, this very issue is a common problem. There might be some nugget package for this kind of task, which we can consume.

@am11
Copy link
Contributor

am11 commented Apr 11, 2014

Here are couple of examples, we can select one and offload the read / write tasks to it:

@am11
Copy link
Contributor

am11 commented Apr 12, 2014

@kgi-cwells, since I can't reproduce this crashing issue reported by many, would you please bare with me and follow these steps:

  • Open VS and WE project.
  • Right click resources > Manage Nuget Packages.
  • Search for TransientFaultHandling.Core and install it.
  • Open webessentials2013\editorextensions\shared\helpers\filehelpers.cs and add these methods at the end of the class and resolve the reference (Ctrl + . => using Microsoft.Practices.TransientFaultHandling;).
  • Under webessentials2013\editorextensions\shared\helpers\ create a file FileTransientErrorDetectionStrategy.cs and replace the template code with this one.
  • On this line, change File to FileHelpers.

Now test if it fixes the issue. :)

@chadwells
Copy link
Author

@am11 - I tried this, and upon my second build of my test project I get pretty much the same error, just different stacktrace with the new code:

System.IO.IOException was unhandled by user code
HResult=-2147024864
Message=The process cannot access the file 'C:\Dev\testerror\testerror\app.js' because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
at System.IO.File.ReadAllText(String path)
at MadsKristensen.EditorExtensions.FileHelpers.<>c__DisplayClass25.b__24() in c:\Dev\WebEssentials2013\EditorExtensions\Shared\Helpers\FileHelpers.cs:line 318
at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
InnerException:

@am11
Copy link
Contributor

am11 commented Apr 13, 2014

@SLaks, I have made some changes you suggested plus the retry logic when file IO exceptions are thrown, using Microsoft Enterprise library. Here is the commit am11@fa7dd65. I tested it a bit to ensure that there is no locking issue. Please review it.

@kgi-cwells, thanks for reverting. Please test with this build http://1drv.ms/1nGnPaW, made for the aforementioned commit, and let us know how does it perform..

@chadwells
Copy link
Author

@am11 - I tested with that provided build and I get crashes with same frequency (either after building just after a build, or after editing and saving a .ts file). Although the trace is different now:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__5(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Just to be safe, I re-tried after disabling the WE extensions and I get no errors/crashes.

@SLaks
Copy link
Collaborator

SLaks commented Apr 14, 2014

@am11 To fix this, you need to add .DontWait() to the entry-point of every async operation that might fail.

(instead of awaiting from an async void)

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

It seems like the issue is either:

  • Some other process has occupied file handler with no sharing. For which it will disregard any call made to open file. This is the exact thing happens to me when I upload visx file from File Explorer to OneDrive.com opened in IE. I drag drop the file and for the subsequent builds, VS throw file in use exception. Closing Both IE and file explorer fix this issue. It could be that @kgi-cwells, has some other extension installed which has file DC handle.
  • The parameter value in transient RetryPolicy ctor need to be fine tuned: PolicyFactory.cs. Currently, the RetryCount is set to five and the time span between each try is 50ms. The other ctor is using backoffs:
public RetryPolicy (
    int retryCount,
    TimeSpan minBackoff,
    TimeSpan maxBackoff,
    TimeSpan deltaBackoff
)

Anyone who can reproduce this issue can play with these parameters to make some progress. It isn't predictable what other process or WE thread might be capturing the file handler at the time of thrown and how persistent/permanent is their bond. Perhaps time delay is not even a solution here?

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

@SLaks, I have changed awaited calls to DontWati in BundleFile.cs and TypeScriptCompilationNotifier.cs with am11@0218448.

Also updated the visx http://1drv.ms/1nGnPaW.

Cc: @kgi-cwells, @RaptorCZ, @blowsie, @joneff, @ShaneGarza, @tomvdk; your feedback would really help!

@joneff
Copy link

joneff commented Apr 14, 2014

@am11 the update no longer crashes VS.

Still, the files are not compiled and the ts template is missing.

@joneff
Copy link

joneff commented Apr 14, 2014

This one happens when I open Sass (scss files) after updating to v.2.0.4


If a sass file has any content e.g. different from mixins VS crashes. If the file has only mixins it's fine.

Happens both with D: and C: system drive.

From event logger

Faulting application name: devenv.exe, version: 12.0.30324.0, time stamp: 0x532f84b4
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18229, time stamp: 0x51fb1116
Exception code: 0xe0434352
Fault offset: 0x0000c41f
Faulting process id: 0x2db4
Faulting application start time: 0x01cf57ccc110a408
Faulting application path: D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
Faulting module path: D:\WINDOWS\syswow64\KERNELBASE.dll
Report Id: 1443cda8-c3c0-11e3-9c25-cc52af4992b0

and also

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at Microsoft.VisualStudio.Editor.Implementation.IVsPrivTextManager.DisplayUnnormalizedLinesDialog(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines)
   at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow+<>c__DisplayClass27.<Init_OnTextBufferLoaded>b__25()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

Another interesting thing is that when I open a mixin file it automatically compiles all sass files that reference it.

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

@joneff, thanks for reverting! :)

Another interesting thing is that when I open a mixin file it automatically compiles all sass files that reference it.

This is due to the Chained compilation feature (disableable in WE settings); which walks through the dependent files and compile them in a separate thread.

Would you please share contents of your SCSS file via http://gist.github.com or http://pastebin.com?

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

@SLaks, some unit tests are failing. One of which is PathNormalizationTest. Now, there is no async void in the call stack except for the test method itself (in other words; no DontWaitable async method).

Moreover, the exception suggests the VSHost is not waiting for async task:

Test Name:  PathNormalizationTest
Test FullName:  WebEssentialsTests.LessCompilationTests.PathNormalizationTest
Test Source:    c:\Users\Adeel\Source\Repos\WebEssentials2013\WebEssentialsTests\Tests\NodeExecutors\LessCompilationTests.cs : line 65
Test Outcome:   Failed
Test Duration:  0:00:09.9597406
Result Message: The test adapter 'VsIdeHostAdapter' threw an exception while running test 'PathNormalizationTest'. Failed to read from an IPC Port: The pipe has been ended.

If I disable settings file (Test > Test Settings), it throws following exception:

Test Name: PathNormalizationTest
Test FullName:  WebEssentialsTests.LessCompilationTests.PathNormalizationTest
Test Source:    c:\Users\Adeel\Source\Repos\WebEssentials2013\WebEssentialsTests\Tests\NodeExecutors\LessCompilationTests.cs : line 65
Test Outcome:   Failed
Test Duration:  0:00:00.0591673
Result Message: 
Test method WebEssentialsTests.LessCompilationTests.PathNormalizationTest threw exception: 
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Adeel\Source\Repos\WebEssentials2013\TestResults\Adeel_ADEEL-HP-PC 2014-04-14 13_24_10\Out\fixtures\less'.
Result StackTrace:  
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
   at WebEssentialsTests.LessCompilationTests.d__d.MoveNext() in c:\Users\Adeel\Source\Repos\WebEssentials2013\WebEssentialsTests\Tests\NodeExecutors\LessCompilationTests.cs:line 65
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

Which is correct as the fixtures directory is not coping under TestResults\~dynamic-slug~\Out.

Do we need Setup script to (recursively) copy fixtures directory in WebEssentialsTests.UnitTests.testsettings?

Momentarily, fixture directory gets copied under WebEssentialsTests\bin\Release(or Debug)\fixtures on build (the post-build robocopy command is working fine).

@joneff
Copy link

joneff commented Apr 14, 2014

@am11 I know about chained compiles, but I thought those work on save basis, where as currently it works on view (open) basis.

See the attached video -- https://dl.dropboxusercontent.com/u/6677802/chained_comile_on_view.swf

On the crashing part, I am still not sure how it happens and I am trimming down a case.

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

@joneff, this is by design. When a CSS preprocessor source file (LESS/SCSS) is opened in editor, WE compiles it in a background and generates its sourcemaps, parse them and enable some enhanced features (CSS specificity, Go To Definition, selector path in tooltip et el.).

@joneff
Copy link

joneff commented Apr 14, 2014

@am11 I tested on another computer with v2.0.3 and WE doesn't work like that. It waits until I save the includes ( _part.scss if we are referring to the example) and then it compiles.

Also, why is it that includes are compiled on open, where as other files are compiled on save? Wouldn't other files feel neglected ;)

I also have a source controlled project with ~1k sass files that all use the same includes and it's a minor nuance to cancel all 1k checkout dialogs just because I opened my mixins to check something.

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

The dialog will only appear if target file (css or js) is opened in editor.

Also, apparently Yes to all will not help in your situation. I guess we need to have an aggregated dialog for all changes, like the one we get when closing VS with pending changes. Here is the previous discussion #284 (comment) and another reason #206 (comment) to have it.

Please don't hesitate in implementing these awesome features and sending PRs. (-8

@chadwells
Copy link
Author

@am11 - With that latest visx build, I finally do not have any crashes of VS, BUT, occaisionally I get the following in my build output window:

1>------ Build started: Project: testerror, Configuration: Debug Any CPU ------
4/14/2014 8:38:17 AM: An exception was thrown when reading C:\Dev\testerror\testerror\app.jsfile: System.IO.IOException: The process cannot access the file 'C:\Dev\testerror\testerror\app.js' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
at System.IO.File.ReadAllText(String path)
at MadsKristensen.EditorExtensions.FileHelpers.d__1e.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MadsKristensen.EditorExtensions.TypeScript.TypeScriptCompilationNotifier.d__8.MoveNext()
1> testerror -> C:\Dev\testerror\testerror\bin\testerror.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

It's still seemingly random though. Sometimes I can edit the .ts file, save, then build and that exception doesn't happen. other times, it does happen. At least devenv.exe isn't crashing now.

@gcastre
Copy link
Contributor

gcastre commented Apr 14, 2014

I have multiple crash here also with the latest nightly.

One is in https://github.com/madskristensen/WebEssentials2013/blob/master/EditorExtensions/CSS/QuickInfo/Selector/SelectorQuickInfo.cs#L81 => sourceMap.MapNodes sourceMap is null so sourceMap.MapNodes raise a NullRef

The second is in https://github.com/madskristensen/WebEssentials2013/blob/master/EditorExtensions/Shared/Margins/CssTextViewMargin.cs#L43 => _compilerResult is null

@am11
Copy link
Contributor

am11 commented Apr 14, 2014

@gcastre please test with this interim build http://1drv.ms/1nGnPaW.

@kgi-cwells, that's some progress (with @SLaks's DontWait() helper method); the major crashes are rescued for your scenario. We need to do more tests to avoid VS crashes in various cases.

To make it more robust, we still might need to figure out if the file capture is really transient, then adjust RetryPolicy and the File IO strategy for this RetryPolicy (as mentioned here: #871 (comment)).

am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 14, 2014
* Uses Enterprise Library for "retry policy".
* Routes all File IO read/write calls to helper.
* Fixes CoffeeScript, SCSS and LESS compilation-
  related issues.
* Fixes TypeScript crashing issues.
* Fixes tests.
* Other minor fixes.
* Targeting madskristensen#871, madskristensen#887, madskristensen#890, madskristensen#897, madskristensen#868 & madskristensen#904.
@gcastre
Copy link
Contributor

gcastre commented Apr 15, 2014

@am11 I've notice that the IntellisenseParser and the ScriptIntellisenseListener share the same code listening to the change on the file. This cause the c# class to be generated in typescript (or javascript) twice. see the change here gcastre@129251e If this is indeed a refactoring mistake I'll make the PR

@am11
Copy link
Contributor

am11 commented Apr 15, 2014

That's a good idea.

However I am unable to reproduce this issue. Here are the steps:

  • Open or create an MVC application in VS 2013 Update 2 RC.
  • Create a .cs file under App_Start and name it CoffeeMinify with the following code:
using System.Web.Optimization;

namespace WebApplication1.App_Start
{
    public class CoffeeMinify : JsMinify
    {
        public CoffeeMinify() { }

        public double MyProperty { get; set; }

    }
}
  • Right click .cs file in Solution Explorer > Web Essentials > Create TypeScript file. It produces the following:
declare module server {
    interface CoffeeMinify {
        MyProperty: number;
    }
}

Do you have different reproduction steps?

We also have IntelliseseGeneration unit tests.

Would you please write a test case which is failing so we can track through it?

OAN, you might find that some 9-13 unit tests are failing. Don't worry about them. VSHost times out on deep async process with following exception:

Test Name:  PathNormalizationTest
Test FullName:  WebEssentialsTests.LessCompilationTests.PathNormalizationTest
Test Source:    c:\Users\Adeel\Source\Repos\WebEssentials2013\WebEssentialsTests\Tests\NodeExecutors\LessCompilationTests.cs : line 65
Test Outcome:   Failed
Test Duration:  0:00:14.3838379

Result Message: The test adapter 'VsIdeHostAdapter' threw an exception while running test 'PathNormalizationTest'. Failed to read from an IPC Port: The pipe has been ended.

Several workarounds for this IPC Port exceptions are available online. We need to find the one for our setup and fix it at some point.

But rest assured, all the intellisense cases are passes. If one fail, keep trying. I closed everything before running UTs to get maximum throughput. But still when VSHost crash from test instance, the test result has some false positives. Selecting small chunks of tests and retrying passed all but 9-13.

Perhaps @DerAlbertCom and @SLaks have some insights..


Finally, since you are looking into intellisense, you might like to take a stab at this feature request #495. 😄

@madskristensen
Copy link
Owner

Fixed in latest nightly

SLaks pushed a commit to SLaks/WebEssentials2013 that referenced this issue May 13, 2014
* Uses Enterprise Library for "retry policy".
* Routes all File IO read/write calls to helper.
* Fixes CoffeeScript, SCSS and LESS compilation-
  related issues.
* Fixes TypeScript crashing issues.
* Fixes tests.
* Other minor fixes.
* Targeting madskristensen#871, madskristensen#887, madskristensen#890, madskristensen#897, madskristensen#868 & madskristensen#904.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants