OOP-Designer is unable to resolve assembly references when CopyLocal = false
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 1d 13m
- Merged PRs (30d)
- 85
Description
### Environment
Version 17.12.3
### .NET version
.NET 8.0
### Did this work in a previous version of Visual Studio and/or previous .NET release?
Yes, in .NET 4.7.2
### Issue description
Hi,
We are currently migrating a WinForms solution from .NET Framework (472) to .NET Core (8.0), but we are having issues with the Out-of-Process Designer resolving assembly references to several DLL's that are the output of **another solution**.
We are opting to do it this way because we still want to maintain backwards compatibility with the Framework edition of our codebase. It is our understanding that the general recommendation is to use NuGet feeds and/or CopyLocal = True for the referenced assemblies, but this does not work for our use case since both methods are disruptive to our workflow.
We are wondering if there is a way to assist the Designer in resolving these assembly references by indicating to it to look for:
`\MyAssembly.dll`
instead of
`C:\Users\\AppData\Local\Microsoft\VisualStudio\17.0_XXXX\WinFormsDesigner\UserAppData\MyAssembly.dll`?
Thanks!
### Steps to reproduce
I have attached a reproduction below that causes the error when I try to add a UserControl. which refers to a class in the external assembly, to a Form.
[WinFormsDesignerIssueRepro.zip](https://github.com/user-attachments/files/18429895/WinFormsDesignerIssueRepro.zip)
### Caveat
I understand this example is quite simple and we could probably work around it by putting the instantiation of `Class1` behind a check for DesignMode, but this would not work in our actual project due to the sheer complexity of refactoring it as such.
## Steps:
1. Build `ClassLibrary` solution => OK
2. Build `WinFormsApp` solution => OK
3. In VS, open `Form1.cs` with the Designer and try to drag the `UserControl1` from the `Toolbox` onto it
4. Observe error indicating that it was unsuccessful.
5. Clicking "OK" displays the empty form without the UserControl => NOK

Some diagnostic output from procmon64.exe that confirms the issue has to to with resolving the assembly reference:

## Temporary Workaround
1. In `WinFormsApp.csproj` do the following:
```
...
..\..\build\ClassLibrary.dll
True
...
```
2. Close all designers
3. Rebuild `WinFormsApp` solution
4. Reopen `Form1.cs` in Designer and try to add the `UserControl1` from the Toolbox onto it => OK

### Diagnostics
```text
[14:50:52.629663] trce: Sending request: DesignerHosts/CreateComponent
[14:50:52.629663] info: [WinFormsApp]: TypeResolution: type = WinFormsApp.UserControl1, TimeTaken = 0 ms.
[14:50:52.629663] trce: DesignerHosts/CreateComponent took 00:00:00.0053744.
[14:50:52.629663] fail: Request failures: DesignerHosts/CreateComponent.
Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[14:50:52.629663] fail: Exception: Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
at Microsoft.DotNet.DesignTools.Client.DesignToolsClient.d__49`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignToolsEndpoints.DesignerHostsImpl.CreateComponent(SessionId sessionId, TypeIdentity type, String name, NameValuePairs defaultValues)
at Microsoft.WinForms.DesignTools.Client.Toolbox.WinFormsToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at Microsoft.DotNet.DesignTools.Client.Designers.ComponentProxyDesigner.CreateTool(ToolboxItem tool, Nullable`1 location, Nullable`1 size, ObjectProxy toolboxSnapArgs)
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
[14:50:52.629663] fail: Exception message = Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
at Microsoft.DotNet.DesignTools.Client.DesignToolsClient.d__49`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
at Microsoft.DotNet.DesignTools.Protocol.Endpoints.DesignToolsEndpoints.DesignerHostsImpl.CreateComponent(SessionId sessionId, TypeIdentity type, String name, NameValuePairs defaultValues)
at Microsoft.WinForms.DesignTools.Client.Toolbox.WinFormsToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at Microsoft.DotNet.DesignTools.Client.Designers.ComponentProxyDesigner.CreateTool(ToolboxItem tool, Nullable`1 location, Nullable`1 size, ObjectProxy toolboxSnapArgs)
For information on how to troubleshoot the designer refer to the guide at https://aka.ms/winforms/designer/troubleshooting.
```
Contributor guide
Assessment
This issue has not been assessed yet.