Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix winform control complie #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

oolanlongoo
Copy link

Link to issue(s) this pull request covers:

Problem

Custom control derived from 'System.Windows.Forms.Control' compilation error

Solution

Modify the judgment condition of 'IsWInForm' to be derived from 'System. Windows. Forms. Control' and contain a field of type 'System. Component. IContainer' with the name 'components'

@ElektroKill
Copy link
Member

ElektroKill commented Mar 31, 2025

Hello, could you please provide test cases which demonstrate the functionality before and after your changes.

Could you also describe why you belive the LoadAllDepdencies command is necessary? dnSpy usually loads all depdendecies as needed.

@oolanlongoo
Copy link
Author

1.Regarding "IsWinform"
If I only judge by whether it inherits from "System.Windows.Forms.Form", I can only compile the "Form" correctly. When I decompile the "UserControl" or "CustomControl", I will get a ".cs" file and possibly an incorrect ".resx" file. So I think the judgment should be made by whether it inherits from "System.Windows.Forms.Control" and whether it contains the "InitializeComponent" method. Regarding the property "components", I've found that it may not necessarily exist in some old projects.

For example, this is my test project.
image

The project after decompilation is only correct for the "Form".
image

After modifying the judgment conditions, I got the correct project.
image

@oolanlongoo
Copy link
Author

2.Regarding the "xaml" type name.
The directory of XAML may not be consistent with the namespace of the XAML type. When they are inconsistent, the complete type obtained through the XAML resource name will be incorrect. The correct XAML type should be extracted from the XAML file.

For example, this is my test project. The namespace of "HomePage" is under "TestView", but the path is under "TestWpf/Views".
image
image

After decompilation, I'll get a ".cs" file and a ".xaml" file that are not related to each other.
image

After using the type extracted from the XAML. Although the path is not exactly the same as the original one, I obtained the correct XAML file.
image

@oolanlongoo
Copy link
Author

3.Regarding The "LoadDependencies"
Recently, I got a job that requires me to decompile all the assemblies of an old project and restore the original code files as much as possible. This project is quite large, with around 400 assemblies. Without this add - in, I would have to click on each dependency one by one to load them. Moreover, some assemblies have common references. In this way, I might need to click thousands of times to load all the dependent projects. Additionally, I may currently receive different versions of this set of assemblies, which means I'll face a lot of repetitive operations. That's why I made this modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants