zspitz / ExpressionTreeVisualizer

Debugging visualizer for expression trees
MIT License
340 stars 26 forks source link

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' #107

Open bartjekwartje opened 4 years ago

bartjekwartje commented 4 years ago

The visualizer used to work, but after not using it for a few weeks, it stopped working.

I'm using Visual Studio 2019. The error (see below) happens in at least two projects (haven't tested any others.) The error happens with 'Target framework' set to:

The following error occurs after selecting the visualizer from the list that appears after clicking the magnifying glass from the watch window:

Error: An unhandled exception of type 'System.Runtime.Serialization.SerializationException' was thrown by the custom visualizer component in the process being debugged.

Additional Information: Type 'System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' is not marked as serializable.

Stack Trace: at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.<>cDisplayClass9_0.b_0(MemberHolder ) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at Microsoft.VisualStudio.DebuggerVisualizers.VisualizerObjectSource.Serialize(Stream serializationStream, Object target) at ExpressionTreeVisualizer.VisualizerDataObjectSource.TransferData(Object target, Stream incomingData, Stream outgoingData) at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.TransferData(Object visualizedObject, Byte[] uiSideData)

zspitz commented 4 years ago

@bartjekwartje

I was unable to reproduce this.

What is the precise version of Visual Studio 2019 that you're using? And what is the precise .NET Framework version you have installed? Both are available via Help -> About Microsoft Visual Studio. Click Copy info and paste it here.

It seems to be because there was a point in time when ValueTuple was not marked serializible. But I'm not sure how that changed all of a sudden.

Do you see this problem in multiple projects? If not, perhaps try deleting the .vs folder in the project.

Perhaps also try deleting and re-downloading the visualizer.

I would greatly appreciate it if you could keep me informed of further developments, thanks.

bartjekwartje commented 4 years ago

I removed the old installation and installed the latest version of the visualizer.

I also took your recommendation of deleting the .vs folders.

Whereas before I said that the error ocurred in two separate projects, it now only appears in one of those projects. (It is possible that in my first post I incorrectly assumed it wasn't working in that one project it now works in.)

In other projects I tested it worked fine.

Precise Info (As requested):

Microsoft Visual Studio Community 2019 Version 16.4.2 VisualStudio.16.Release/16.4.2+29613.14 Microsoft .NET Framework Version 4.8.03761

Installed Version: Community

Azure App Service Tools v3.0.0 16.4.457.38025 Azure App Service Tools v3.0.0

C# Tools 3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

NpgsqlVSPackage Extension 1.0 NpgsqlVSPackage Visual Studio Extension Detailed Info

NuGet Package Manager 5.4.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 16.0.61912.09160 Microsoft SQL Server Data Tools

Visual Basic Tools 3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6 16.4.0-beta.19556.5+e7597deb7042710a7142bdccabd6f92b0840d354 Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

VsVim 2.8.0.0 VsVim is a Vim emulator for Visual Studio

zspitz commented 4 years ago

@bartjekwartje Thanks for your patience. Do you think you could upload here up a minimal project that reproduces the problem?

zspitz commented 4 years ago

@bartjekwartje Could you download the visualizer once more and try again?

bartjekwartje commented 4 years ago

@zspitz I followed up on your request to download the visualizer once more and try again. The following describes the steps I undertook and what these resulted in.

I downloaded the zip-file at:

https://github.com/zspitz/ExpressionTreeVisualizer/releases/download/1.7.91/ExpressionTreeVisualizer.2019.zip

Quit visual studio

Then copied the zip's tree/contents to: xx:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Packages\Debugger\Visualizers

Restarted Visual studio

Ran my code and set a breakpoint on a line with the following code: lambda = Expression.Lambda<Func<payments, bool>>(methodExp, param);

Added 'lambda' to the watch window.

Clicked on the Expression Tree Visualizer Magnifying Glass, which then presented me three visualizers to pick from: Readable Expressions Visualizer Expression Tree Visualizer Readable Expressions Visualizer

Note that 'Readable Expressions Visualizer' appears twice. After selecting any of those two, a dialog appears showing information which seems to indicate that that visualizer does work.

But after selecting 'Expression Tree Visualizer' a dialog opens showing the following text:

Unable to load the custom visualizer.

Additional information:

Could not load type 'ExpressionTreeVisualizer.Serialization.VisualizerDataOptions' from assembly 'ExpressionTreeVisualizer.Debuggee, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Learn more about managed custom visualizers

Then I quit visual studio.

Removed the files I copied to: c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Packages\Debugger\Visualizers

Renamed the offending project's .vs folder

After running the project again, breaking into it and putting 'lambda' in the watch window, I can still choose from three visualizers, including ExpressionTreeVisualizer. Selecting it shows a dialog with the following error information:

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' was thrown by the custom visualizer component in the process being debugged.

Additional Information: Type 'System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' is not marked as serializable.

Stack Trace at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.<>cDisplayClass9_0.b_0(MemberHolder ) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at Microsoft.VisualStudio.DebuggerVisualizers.VisualizerObjectSource.Serialize(Stream serializationStream, Object target) at ExpressionTreeVisualizer.VisualizerDataObjectSource.TransferData(Object target, Stream incomingData, Stream outgoingData) at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.TransferData(Object visualizedObject, Byte[] uiSideData)

Then I discover a second folder that contains your visualizer from 30-12-2019:

xx:\Users\xx\Documents\Visual Studio 2019\Visualizers\

I delete the visualizer from that folder and its three subfolders (4 files in total).

After running the project again, breaking into it and putting 'lambda' in the watch window, the options shown do not include ExpressionTreeVisualizer anymore.

I again copy the files from the zip-file mentioned above to the first folder mentioned above.

After running the project again, breaking into it and putting 'lambda' in the watch window, I can choose from three visualizers again, including ExpressionTreeVisualizer. Selecting it shows a dialog with the following error information:

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' was thrown by the custom visualizer component in the process being debugged.

Additional Information: Type 'System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' is not marked as serializable.

Stack Trace at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.<>cDisplayClass9_0.b_0(MemberHolder ) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at Microsoft.VisualStudio.DebuggerVisualizers.VisualizerObjectSource.Serialize(Stream serializationStream, Object target) at ExpressionTreeVisualizer.VisualizerDataObjectSource.TransferData(Object target, Stream incomingData, Stream outgoingData) at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.TransferData(Object visualizedObject, Byte[] uiSideData)

I copy the files from the zip-file mentioned above to the second folder mentioned above. (xx:\Users\xx\Documents\Visual Studio 2019\Visualizers)

After running the project again, breaking into it and putting 'lambda' in the watch window, I can, as before, choose from three visualizers, including ExpressionTreeVisualizer. Selecting it shows a dialog with the following error information:

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' was thrown by the custom visualizer component in the process being debugged.

Additional Information: Type 'System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' is not marked as serializable.

Stack Trace at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.<>cDisplayClass9_0.b_0(MemberHolder ) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at Microsoft.VisualStudio.DebuggerVisualizers.VisualizerObjectSource.Serialize(Stream serializationStream, Object target) at ExpressionTreeVisualizer.VisualizerDataObjectSource.TransferData(Object target, Stream incomingData, Stream outgoingData) at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.TransferData(Object visualizedObject, Byte[] uiSideData)

After all that I opened a different project. There the visualizer worked perfectly.

@zspitz As for your request to create a minimal package. It seems a lot of work. But I might try in the future.

zspitz commented 4 years ago

Let me sum up my understanding of the current situation:

In a project targeting .NET Framework 4.7.2, you're getting the same SerializationException message, whether you install the visualizer in the Visualizers subfolder under Documents, or the Visualizer subfolder in the VS install path.

I don't understand what is going on. There was a brief period of time when ValueTuple wasn't marked as serializable (I think it was after .NET Framework 4.7); but that was fixed since 4.7.2. As long as you have 4.7.2 installed on your machine, it should work, even for projects targeting 4.7.1 and earlier.

@bartjekwartje Could I trouble you again to clear out both Visualizer subfolders, and re-download and try the latest release? Warning: Don't delete all the files in the Visualizer subfolder, only those that start with ExpressionTreeToString. There may be other visualizers in that subfolder, such as the built-in WPF tree visualizer and the DataSet visualizer.

(NB I am unaffiliated with the ReadableExpressions visualizer; you might want to post an issue about the duplicate menu entries there.)

zspitz commented 3 years ago

@bartjekwartje What is the current status? Does the visualizer work for you? I may add a reference to the NuGet ValueTuple package, which uses the value tuple provided by the target framework if available, but will provide it's own implementation if needed.

bartjekwartje commented 3 years ago

I believe the cause lies in inclusion of entity framework in a project.

On Friday, November 6, 2020, Zev Spitz notifications@github.com wrote:

@bartjekwartje https://github.com/bartjekwartje What is the current status? Does the visualizer work for you? I may add a reference to the NuGet ValueTuple package, which uses the value tuple provided by the target framework if available, but will provide it's own implementation if needed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zspitz/ExpressionTreeVisualizer/issues/107#issuecomment-722946095, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2CUSG5W3PZUS37RIYTFRTSOOXCBANCNFSM4LD5H7VA .

zspitz commented 3 years ago

Could you prepare a sample project, reproducing the issue? If not, I'll have to close this issue.

Saragani commented 7 months ago

If your App Config file contains the following configuration under assemblyBinding, then remove it:

  <dependentAssembly>
    <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
  </dependentAssembly>

I've encountered the same issue with a code that worked for 10 years and then stopped working after the configuration above was added (probably automatically by visual studio) to the app config. This was as well an issue with Binary Formatter