title: c# System.OutOfMemoryException in mscorlib.dll
body: <p>I am using VS 2017. I am getting "OutOfMemory in mscorlib.dll" exception in my vsix project. I am using Roslyn in this project, below is my method to find Field Declaration and references. </p>
  
  <pre><code>public static async Task FindFieldDeclarationAndReferencesAsync(string solutionPath, List&lt;Violation&gt; violations) 
  {           
      var msWorkspace = MSBuildWorkspace.Create();
      var solution = await msWorkspace.OpenSolutionAsync(solutionPath);***//The solution I am passing to this workspace is 1 GB***
      var documents = solution.Projects.SelectMany(x =&gt; x.Documents).ToList();
  
      foreach (var violation in violations)//violations.Count is approximately 10
      {
          var classFile = documents.Where(x =&gt; x.FilePath == violation.FilePath).FirstOrDefault();
          var model = await classFile.GetSemanticModelAsync();
          var root = await classFile.GetSyntaxRootAsync();
          var classDeclarationNode = root.DescendantNodes().OfType&lt;ClassDeclarationSyntax&gt;().Where(x =&gt; x.Identifier.Text == violation.ClassName).FirstOrDefault();
  
          var fieldDeclarationNodeList = classDeclarationNode.DescendantNodes().OfType&lt;FieldDeclarationSyntax&gt;().Where(m =&gt; m.Modifiers.ToString().Contains("public const")).SelectMany(x =&gt; x.Declaration.Variables.Where(y =&gt; y.Identifier.Text == violation.FieldName)).FirstOrDefault();
  
          ISymbol fieldSymbol = model.GetDeclaredSymbol(fieldDeclarationNodeList);
          var fieldReferences = await SymbolFinder.FindReferencesAsync(fieldSymbol, solution);
          violation.FieldDeclaration = fieldDeclarationNodeList;
          violation.Replacement = Helpers.GetIdentifierReplacement(violation.FieldName);
          violation.References = fieldReferences.SelectMany(item =&gt; item.Locations).ToList();
      }               
  }
  </code></pre>
  
  <p>Am I getting this exception as the solution size is 1 GB which is passed to Roslyn while creating workspace?</p>
  
  <p><strong>Exception Details:</strong></p>
  
  <pre><code>System.OutOfMemoryException
    HResult=0x8007000E
    Message=Exception of type 'System.OutOfMemoryException' was thrown.
    Source=mscorlib
    StackTrace:
     at System.Threading.ExecutionContext.Capture(StackCrawlMark&amp; stackMark, CaptureOptions options) in f:\dd\ndp\clr\src\BCL\system\threading\executioncontext.cs:line 1281
     at System.Threading.ExecutionContext.FastCapture() in f:\dd\ndp\clr\src\BCL\system\threading\executioncontext.cs:line 1190
     at System.Runtime.CompilerServices.AsyncMethodBuilderCore.GetCompletionAction(Task taskForTracing, MoveNextRunner&amp; runnerToInitialize) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs:line 916
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AwaitUnsafeOnCompleted[TAwaiter,TStateMachine](TAwaiter&amp; awaiter, TStateMachine&amp; stateMachine) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs:line 543
     at System.Runtime.CompilerServices.AsyncMethodBuilderCore.&lt;&gt;c.&lt;ThrowAsync&gt;b__6_1(Object state) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs:line 1034
     at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) in f:\dd\ndp\clr\src\BCL\system\threading\threadpool.cs:line 1273
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in f:\dd\ndp\clr\src\BCL\system\threading\executioncontext.cs:line 954
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in f:\dd\ndp\clr\src\BCL\system\threading\executioncontext.cs:line 901
     at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() in f:\dd\ndp\clr\src\BCL\system\threading\threadpool.cs:line 1250
     at System.Threading.ThreadPoolWorkQueue.Dispatch() in f:\dd\ndp\clr\src\BCL\system\threading\threadpool.cs:line 819
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() in f:\dd\ndp\clr\src\BCL\system\threading\threadpool.cs:line 1161
  </code></pre>
  
  <p>I checked the Handles in TaskManager for my process and below are the values.</p>
  
  <p><a href="https://i.stack.imgur.com/u1qCZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u1qCZ.png" alt="TaskManager-handles"></a></p>
  
  <p>I want to get out of this exception. Please suggest a solution.</p>