Skip to content

Designer not work when control referenced by project #5

@kirsan31

Description

@kirsan31

V.S. - all versions.
Commit to test: https://github.com/kirsan31/winforms-datavisualization/tree/6f35dccb327f78f889797ce9d610764199edecab

See DesignerTest project.
If chart control referenced by project (default way):

<ItemGroup>
  <ProjectReference Include="..\src\System.Windows.Forms.DataVisualization\ChartWin.csproj" />
</ItemGroup>

When dragging a control onto a form, an exception occurs:
Method not found: 'System.CodeDom.CodeExpression Microsoft.DotNet.DesignTools.Serialization.CodeDomSerializerBase.SerializeToExpression(System.ComponentModel.Design.Serialization.IDesignerSerializationManager, System.Object)'.

If chart control referenced by dll:

<ItemGroup>
  <Reference Include="System.Windows.Forms.DataVisualization">
    <HintPath>..\src\System.Windows.Forms.DataVisualization\bin\Debug\net6.0-windows\System.Windows.Forms.DataVisualization.dll</HintPath>
  </Reference>
</ItemGroup>

all work fine.

Top call stack from debug:

Method not found: 'System.CodeDom.CodeExpression Microsoft.DotNet.DesignTools.Serialization.CodeDomSerializerBase.SerializeToExpression(System.ComponentModel.Design.Serialization.IDesignerSerializationManager, System.Object)'.

   at System.Windows.Forms.Design.DataVisualization.Charting.ChartWinDesignerSerializer.Serialize(IDesignerSerializationManager manager, Object value) in D:\save\work\main\winforms-datavisualization\src\System.Windows.Forms.DataVisualization\Design\WinChartDesignerSerializer.cs:line 83
   at Microsoft.DotNet.DesignTools.Serialization.CodeDomSerializationStore.ComponentListCodeDomSerializer.Serialize(IDesignerSerializationManager manager, IDictionary objectData, IDictionary objectState, IList shimObjectNames)

I think this line is here:

Full call stack from debug:

   Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Serialization.CodeDomSerializationStore.ComponentListCodeDomSerializer.Serialize(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, System.Collections.IDictionary objectData, System.Collections.IDictionary objectState, System.Collections.IList shimObjectNames)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Serialization.CodeDomSerializationStore.Close()
System.ComponentModel.TypeConverter.dll!System.ComponentModel.Design.Serialization.SerializationStore.Dispose(bool disposing) Line 53
	at /_/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/SerializationStore.cs(53)
System.ComponentModel.TypeConverter.dll!System.ComponentModel.Design.Serialization.SerializationStore.System.IDisposable.Dispose() Line 45
	at /_/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/SerializationStore.cs(45)
System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.UndoUnit.AddRemoveUndoEvent.AddRemoveUndoEvent(System.ComponentModel.Design.UndoEngine engine, System.ComponentModel.IComponent component, bool add) Line 1124
	at /_/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/UndoEngine.cs(1124)
System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.UndoUnit.ComponentAdded(System.ComponentModel.Design.ComponentEventArgs e) Line 677
	at /_/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/UndoEngine.cs(677)
System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.OnComponentAdded(object sender, System.ComponentModel.Design.ComponentEventArgs e) Line 323
	at /_/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/UndoEngine.cs(323)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Host.RemoteDesignerHost.OnComponentAdded(System.ComponentModel.IContainer container, System.ComponentModel.IComponent component, System.ComponentModel.Design.IDesigner designer)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Host.RemoteDesignerHost.AddToContainerPostProcess(System.ComponentModel.IComponent component, string name, System.ComponentModel.IContainer containerToAddTo)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Host.RemoteDesignerHost.Add(System.ComponentModel.IComponent component, string name)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Host.RemoteDesignerHost.CreateComponent(System.Type componentClass, string name)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Utilities.IDesignerHostExtensions.CreateAndInitializeComponent(System.ComponentModel.Design.IDesignerHost designerHost, System.Type type, string name, System.Collections.IDictionary defaultValues)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignerHosts.CreateComponentHandler.HandleRequest(System.ComponentModel.Design.IDesignerHost designerHost, Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignerHosts.CreateComponentRequest request)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignerHosts.DesignerHostRequestHandler<System.__Canon, System.__Canon>.HandleRequest(System.__Canon request)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Protocol.Endpoints.RequestHandler<Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignerHosts.CreateComponentRequest, Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignerHosts.CreateComponentResponse>.Microsoft.DotNet.DesignTools.Protocol.Endpoints.IRequestHandler.HandleRequest(Microsoft.DotNet.DesignTools.Protocol.Endpoints.Request request)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Protocol.Endpoints.RequestManager.HandleRequestAsync(string name, Microsoft.DotNet.DesignTools.Protocol.Endpoints.Request request)
[Resuming Async Method]
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183
	at /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(183)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.DotNet.DesignTools.Protocol.Endpoints.Response>.AsyncStateMachineBox<Microsoft.DotNet.DesignTools.Protocol.Endpoints.RequestManager.<HandleRequestAsync>d__10>.MoveNext(System.Threading.Thread threadPoolThread) Line 324
	at /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs(324)
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Line 6492
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs(6492)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183
	at /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(183)
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() Line 6577
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs(6577)
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13357
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs(13357)
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1507
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/ScrollableControl.cs(1507)
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Line 6632
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Form.cs(6632)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Server.Window.ServerWindow.WndProc(ref System.Windows.Forms.Message m)
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 117
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlNativeWindow.cs(117)
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 370
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/NativeWindow.cs(370)
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(System.UIntPtr dwComponentID, Interop.Mso.msoloop uReason, void* pvLoopData) Line 346
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Application.ComponentManager.cs(346)
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1117
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Application.ThreadContext.cs(1117)
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 981
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Application.ThreadContext.cs(981)
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) Line 1195
	at /_/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs(1195)
Microsoft.DotNet.DesignTools.Server.dll!Microsoft.DotNet.DesignTools.Server.DesignToolsServer.StartUIThreadAsync.AnonymousMethod__1()
System.Private.CoreLib.dll!System.Threading.Thread.StartHelper.Callback(object state) Line 42
	at /_/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs(42)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183
	at /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(183)
System.Private.CoreLib.dll!System.Threading.Thread.StartCallback() Line 105
	at /_/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs(105)
[Async Call Stack]
[Async] StreamJsonRpc.dll!StreamJsonRpc.JsonRpc.DispatchIncomingRequestAsync(StreamJsonRpc.Protocol.JsonRpcRequest request)
[Async] StreamJsonRpc.dll!StreamJsonRpc.JsonRpc.HandleRpcAsync(StreamJsonRpc.Protocol.JsonRpcMessage rpc)

Very interesting thing to note.

If project (DesignerTest) contains no reference to chart control (we drag it to the form by first time). That control will be successfully dragged to the form, a project reference will be added and the designer will work. BUT, if we close the solution, open it again and try to do something in the designer - the V.S. will crash!

------------UPD------------

I found what line of code is responsible of this bug.

// Add assignment statement for the DataSource property
System.CodeDom.CodeExpression targetObject =
base.SerializeToExpression(manager, value);

Simplified code:

public override object Serialize(IDesignerSerializationManager manager, object value)
{
    Diagnostics.Trace.WriteLine("Context " + manager.Context.Current + "; value " + value);
    Chart chart = value as Chart;

    object result = null;
    CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Chart).BaseType, typeof(CodeDomSerializer));
    if (baseSerializer is not null)
    {
        result = IsSerialized(manager, value) ? GetExpression(manager, value) : baseSerializer.Serialize(manager, value);
        if (chart is not null && chart.DataSource is string dSstring && dSstring != "(none)" && result is CodeDom.CodeStatementCollection statements)
        {
            CodeDom.CodeExpression targetObject = base.SerializeToExpression(manager, value); // the problem in this line!
            //if (targetObject is not null)
            //{
            //    CodeDom.CodeAssignStatement assignStatement = new CodeDom.CodeAssignStatement(
            //        new CodeDom.CodePropertyReferenceExpression(targetObject, "DataSource"),
            //        new CodeDom.CodePropertyReferenceExpression(new CodeDom.CodeThisReferenceExpression(), dSstring));
            //    statements.Add(assignStatement);
            //}
        }
    }

    return result;
}

With code above we have this bug and Diagnostics line (Diagnostics.Trace.WriteLine("Context " + manager.Context.Current + "; value " + value);) will never appear and DataSource is null of course. So Serialize method simply never called.
If comment out this line:

CodeDom.CodeExpression targetObject = base.SerializeToExpression(manager, value);

we have no problem.

So, my thots that this line (when referenced by project) somehow instructs V.S. to call this code from .net framework (via reflection)???

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdesignerIssue / question with new WinForms Designer.external issueAn issue is caused by an external system and won't be fixed in this repo.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions