How to solve the "unable to load one or more of the types in the assembly" problem!

Source: Internet
Author: User
These two days have been a headache for "unable to load one or more of the types in the assembly". I believe that there is a lot of need to use reflection to load assembly and dynamically call ass. gettypes () or ass. friends of GetType (string) or createinstance () may encounter this annoying problem like me. This problem is very concealed. Generally, if you encounter this problem during execution of GetType or createinstance, if you choose not to prompt for an error, Program It simply returns NULL. In addition, no documents have been found describing the cause.

Let's take a look at the typical error scenarios:

Assembly ass = assembly. LoadFile (asspath );
T = ass. GetType (typename, false );

It's so obviousCodeBut often this "unable to load one or more of the types in the assembly" error occurs. When the specified type is clearly in this Assembly, an error is reported and null is returned. In addition, some assemblies run normally, while others do not, or even, some sometimes report errors normally, which is nothing to say to Bill.

After several twists and turns, we found the solution: replace LoadFile with loadfrom:

Assembly ass = assembly. loadfrom (asspath );
T = ass. GetType (typename, false );

It is really simple. I want to laugh, but I have found countless circles on the Internet, but countless friends have not tried to do so and I am worried.

Compare the descriptions of Assembly. LoadFile and assembly. loadfrom in msdn:

Assembly. LoadFile:
Note: This namespace, class, or member is supported only in version 1.1 of the. NET Framework.
Loads the contents of an assembly file.

Assembly. loadfrom:
Loads an assembly.

In addition, there are no different instructions!

Without saying anything, you can only sigh that Uncle Bill has been playing the game again ~~

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.