question

NovumRoboticsAutomation-3337 avatar image
0 Votes"
NovumRoboticsAutomation-3337 asked NovumRoboticsAutomation-3337 edited

Visual Studio 2022 Visual Basic Error in Loading a UserControl in another UserControl

I have a solution with several projects in visual basic.
I made it in visual studio 2019 community and now I try to continue developping it in visal studio 2022 community.

When I run my solution in Debug mode in visual studio 2022, then it works fine.

However when I try to open an user control 'UserControl_A', which I have defined, and this user control 'UserControl_A' contains another user control, say 'UserControl_B', then I get a designer error.
So I removed the user control 'UserControl_B' from 'UserControl_A.designer.vb'.

Then I opened the designer of 'UserControl_A'.

Next I get user control 'UserControl_B' from the ToolBox and put it at the correct place in UserControl_A, and then I get the following error:
Failed to create component 'UserControl_B'. The error message follows: 'system.IO.FileNotFoundException: Could not load file or assembly 'name of assembly in my solution'

UserControl_B uses objects from 'name of assembly in my solution'
UserControl_A and UserControl_B are in the same project. When I open UserControl_B in Design mode, then it opens correctly, no error.

So when running the program then this 'assembly in my solution' can be found by visual studio, but when I try to put UserControl_B in UserControl_A it fails to do so.

Can anyone help me, how to fix this?
Thanks.

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JiachenLiMFST-9349 avatar image
0 Votes"
JiachenLiMFST-9349 answered NovumRoboticsAutomation-3337 commented

Hi @NovumRoboticsAutomation-3337 ,

Make sure you don't check debug folder and the output mode is release.
In case of debug mode, the .net looking for required dlls in bin/debug folder but the output mode is release and these ddls will be copied to bin/release folder. So you have to copy ddls into bin/debug folder.

From "Unable to create component" error
Best Regards.
Jiachen Li

If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

All the required ddl's were and are in the bin/Debug folder.
And the problem still remains.
I hope you have an other suggestion.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 NovumRoboticsAutomation-3337 ·

To work around the problem, try inserting the control programmatically:

Dim b = New UserControl_B
b.Left = 10
b.Top = 20
Controls.Add(b)

It can be done in the constructor or Load event of UserControl_A.

Also check if the problem persists in case of new projects and controls.


0 Votes 0 ·

@Viorel-1

Thanks this solution works, it is not a pretty one ;-), but it will do.
I can work on UserControl_A in design mode.

0 Votes 0 ·
NovumRoboticsAutomation-3337 avatar image
0 Votes"
NovumRoboticsAutomation-3337 answered NovumRoboticsAutomation-3337 edited

I have checked in some other projects of mine, and the Problem of a UserContorl in a UserControl exists there to.

So, I very much hope that the problem will be fixed in Visual Studio 2022.
I

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NovumRoboticsAutomation-3337 ,
I tested putting a UserControl2 containing a button into UserControl1 and no errors occurred. In VS2022 with .net Framework4.8.
Could you please provide more information about your project's environment and assembly usage so that we can reproduce your problem?

0 Votes 0 ·

I use .Net Framework 4.7.1 and the TargetCPU = x86 for all assemblies in mu solution

And as I described in UserControl_B I include another assembly, which includes also other assemblies'

The thing is, when I open the Solution in Visual Studio 2019 there is no problem, then I can open the UserControl_A', and I dont get an error, I can open the form with UserContorl_A and it opens in the Design mode.

So something has changed in Visual Studio 2022, that is what i think.


Some extra information:
When I open the UserControl_A in Design mode, I get 2 errors : the first is that its missing the assembly I mentioned earlier, the second error is: the control variable UC_B (As UserCotnrol_B) is either undeclared or was never assigned.
The line in the source code is: Me.TabPageDrawing.Controls.Add(Me.UC_B)
Apparently the line where the control is created did not fail?


I tried something else: All the files of the project of the Assembly I refer in UserControl_B, I put in the same project as UserControl_A and UserControl_B and then there error dissapears.
But this is not how I want to solve this problem.

I am stuck now.



0 Votes 0 ·
JiachenLiMFST-9349 avatar image JiachenLiMFST-9349 NovumRoboticsAutomation-3337 ·

Hi @NovumRoboticsAutomation-3337 ,
It looks like a bug in Visual Studio 2022.
It is recommended to post issues to the Visual Studio Developer Community.


0 Votes 0 ·
Show more comments