question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OutOfMemoryException in XAML designer due to failed assembly reference resolution based on PackageReference tag

See original GitHub issue

XAML Workflow Activity designer 100% throws OutOfMemoryException and crashes when some specific NuGet packages are referred through PackageReference (NOT with packages.config) using the “old” project file format (<Project ToolsVersion="15.0" ...> and NOT <Project Sdk="Microsoft.NET.Sdk">).

I think this is caused by some assembly reference resolution error in the new PackageReference related code and related to #1244, #1499

Steps to reproduce:

  • VS 2017 (any VS 15.x version I’ve tested fails)
  • fresh new empty solution with Workflow Activity library added from original VS template (net461, though any version I’ve tested fails)
  • add any ONE of these NuGet packages with PackageReference (NOT with packages.config)
    • Microsoft.Orleans.Core (v1.5.3, though any version I’ve tested fails)
    • Microsoft.Orleans.Core.Abstractions (v2.0.0-beta3, though any version I’ve tested fails)
    • Abp (v3.4.0) + add reference to System.Drawing
    • Dapper (v1.50.4)
    • Orleans.Activities (v0.3.0)
  • open the empty Activity1.xaml in the designer

Instead of opening the designer, VS says:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at VSLangProj.Reference.get_PublicKeyToken()
   at Microsoft.VisualStudio.Activities.Helper.CreateAssemblyNameFromReference(Reference r)
   at Microsoft.VisualStudio.Activities.Helper.GetReferenceAssemblies(VSProject project)
   at Microsoft.VisualStudio.Activities.EditorPane.get_ReferencedAssemblies()
   at Microsoft.VisualStudio.Activities.EditorPane.ResetShadowCopyPath()
   at Microsoft.VisualStudio.Activities.EditorPane.CreateWorkflowDesignerInIsolatedMode()
   at Microsoft.VisualStudio.Activities.EditorPane.Microsoft.VisualStudio.Shell.Interop.IPersistFileFormat.Load(String fileName, UInt32 formatMode, Int32 readOnly)

Some of the above packages (Microsoft.Orleans.Core, Orleans.Activities, Abp) also causes the “The referenced component ‘System.Net.Http’ could not be found.” warning, so after adding the below code to the end of the project files, the warning disappears, but the XAML designer still crashes:

  <Target Name="UpdateOriginalItemSpecs" AfterTargets="ResolveAssemblyReferences">
    <ItemGroup>
      <ReferencePath>
        <OriginalItemSpec>%(ReferencePath.FileName)</OriginalItemSpec>
      </ReferencePath>
    </ItemGroup>
  </Target>

But 2 warnings remain even after adding the above target to the project file (I think the XAML designer uses some different target for assembly resolution):

  • Could not run workflow validation because file ‘System.Net.Http, PublicKeyToken=b03f5f7f11d50a3a’ has an incorrect format. This will not prevent workflows from running; but any workflow that has a validation error will fail at runtime. If the file is a platform-specific library or executable, consider building the project using MSBuild.exe from a command prompt of the targeted platform.
  • Could not compile workflow expressions because file ‘file:///C:\Users\lmagyar.nuget\packages\system.net.http\4.3.0\ref\net46\System.Net.Http.dll’ has an incorrect format. Workflows in this project may still run, if they do not require expression compilation. If the file is a platform-specific library or executable, consider building the project using MSBuild.exe from a command prompt of the targeted platform.

Note: referring Microsoft.Orleans.Core.Abstractions or Dapper doesn’t cause any warning, the designer simply crashes. Adding the above target workaround, doesn’t change anything.

I’ve tried to investigate:

  • I’ve added all the ~50 nuget packages that is referenced through Microsoft.Orleans.Core (based on the packages.config in another project), with PackageReference, no problem, but finally adding Microsoft.Orleans.Core results in the exception
  • I’ve tried several assembly binding redirects, nothing changes, exception
  • devenv.exe /safemode, exception
  • I’ve also tried to debug devenv, but I think due to CreateWorkflowDesignerInIsolatedMode(), I wasn’t able to catch the exception
  • MSBuild.exe builds without any warning

This error also reported multiple times at several places:

Using the new project file format (<Project Sdk="Microsoft.NET.Sdk">) is not an option, because it doesn’t contain the XamlAppDef BuildAction and though the XAML designer starts without crash, it doesn’t resolve any assembly, so useless. Using packages.config as workaround is awfully slow and painful.

Maybe @dmetzgar can add some insights about the internals of the XAML Workflow Activity designer.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sharwellcommented, Feb 4, 2018

@lmagyar I tracked down the source of this bug in our internal code and assigned it a team that should be able to help out. Your bug report is outstanding, and I’m sorry to see that it took so long to get eyes on it. I’m going to start a separate internal discussion related to avoiding the type of delay that occurred in reviewing your feedback items.

/cc @Pilchie

1reaction
sharwellcommented, Feb 4, 2018

On it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

WPF Xaml Designer is getting Out Of Memory due to ...
1 Answer 1 ... Set the "Build Action" to "Content". Indeed, if you set Build Action to resources, it will be embedded resource...
Read more >
the app builds without issue yet XAML Designer still says ...
Designer complains "Some assembly references are missing" even though Visual Studio can build, compile, link, and run the app without issue ...
Read more >
MSB3277: Found conflicts between different versions of ' ...
This error occurs during a build when more than one version of the same dependent assembly is referenced in a build of the...
Read more >
https://raw.githubusercontent.com/dotnet/samples/m...
TestThreadCollectionBehavior failed in CI Failed test: System. ... The located assembly's manifest definition does not match the assembly reference.
Read more >
Referencing a Specific Assembly from a NuGet Package
In this post, I'll describe a little trick I used while building a Rider plugin for XAML Styler, which is referencing a specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found