Reflector decompile WinForm Program rebuild project resources and local resources

Source: Internet
Author: User
Tags reflector

Tools: vs2012,. NET Reflector8.1.0.35

To resolve the issue:

Code generated by reflector decompile can compile and display the form's local resources and project resource pictures

First, the test project

Two images placed in the project resources and the local resources of the form

Project resource file:

<data name= "Chrysanthemum" type= "System.Resources.ResXFileRef, System.Windows.Forms" >    <value> \resources\chrysanthemum.jpg; System.Drawing.Bitmap, System.Drawing, version=4.0.0.0, Culture=neutral, Publickeytoken=b03f5f7f11d50a3a</value >  </data>  <data name= "Resources" type= "System.Resources.ResXFileRef, System.Windows.Forms" >    <value>, .... \ resource. txt; System.String, mscorlib, version=4.0.0.0, Culture=neutral, publickeytoken=b77a5c561934e089;gb2312</value>  </data>

Local resource file:

<data name= "Picturebox2.image" type= "System.Drawing.Bitmap, System.Drawing" mimetype= "application/ X-microsoft.net.object.bytearray.base64 ">    <value>        /9j/4aaqskzjrgabageayabgaad/ 7gaoqwrvymuazaaaaaab/+eo5kv4awyaae1nacoaaaaiaaqbmgac ........ ....................... </value>

Second, Reflector anti-compilation

On the. resources file, right-click = "Open with=" vs2012, you can view the resource files in VS and generate. resx files in the C:\Reflector\Exports directory, such as:

C:\Reflector\Exports\ResxDemo.Form1.resources.resx

You can also use the ResGen command to generate a ResX file

Select Resxdemo Project Export source code in the vs2012 open, then generally can be compiled through, and can run. However, when you open the Form editor, an error occurs that indicates that the resource could not be found.

There are several differences between the anti-compilation project and the original project:

1. The original project \properties\resources.resx resource file is not available, in the project root directory more than a ResxDemo.Properties.Resources.resources file

2. The original project Form1.resx and Form2.resx resource files are not, more than two. resources file

3. There is a resources folder in the original project to hold the picture of the project resource, the folder is not after the anti-compilation

4. Original project file. The resource reference method in Csproj is like this

<embeddedresource include= "Form1.resx" >      <DependentUpon>Form1.cs</DependentUpon>    </ embeddedresource>    <embeddedresource include= "Form2.resx" >      <dependentupon>form2.cs</ dependentupon>    </EmbeddedResource>    <embeddedresource include= "Properties\resources.resx" >      <Generator>ResXFileCodeGenerator</Generator>      <LastGenOutput> resources.designer.cs</lastgenoutput>      <SubType>Designer</SubType>    </ Embeddedresource>

This is the inverse of the compilation.

  <embeddedresource include= "ResxDemo.Form1.resources"/>   <embeddedresource include= " ResxDemo.Form2.resources "/>   <embeddedresource include=" ResxDemo.Properties.Resources.resources "/>

The *.resx file is a resource description file in XML format, and the *.resources file is a compiled binary resource file.

You can run and display the picture because the runtime extracts resources from the. resources file, but you cannot read the binaries at design time, so the following errors are reported.

The type "ResxDemo.Properties.Resources" does not have a property named "Chrysanthemum".

To resolve issues that the project resources cannot find:

1. Use the ResGen command to generate the Resources.resx file and copy it to the properties directory

2. Delete the ResxDemo.Properties.Resources.resources and Resource.cs files from the project

3. Include Resource.resx in the project, double-click Open, modify the access modifier to internal, save it to automatically generate Resource.Designer.cs files.

Rebuild the project and reopen Form1. You can see that the pictures using project resources are already displayed.

At this point, the use of local resources is neither error nor display, but the operation can be displayed, because it is still used by the. resources resource file.

Resolve issues that are not found on local resources:

1. Use the ResGen command to generate the Form1.resx file and copy it to the Form1.cs directory

2. Remove the * from the project. Form1.resources file

3. Include the Form1.resx file from the project, rebuild the project, and reopen the form to display the picture.

Reflector decompile WinForm Program rebuild project resources and local resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.