简体   繁体   中英

Reflecting an older version of System.dll

I have a build activity that reflects one of our libraries to compare it against a domain definition. During the reflection, whenever I try to reflect Uri it returns as RunTimePropertyInfo instead of Uri and whenever I check any of the reflected properties I get an exception stating ...

"Could not load file or assembly 'System, Version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e, retargetable=yes"

The build activity is compiled with System.dll version 4.0.0.0. I suspect this is the issue. Is there a way for me to reflect a type on an older version of System.dll.

So far this has only failed with Uri. Any ideas?

I think there is versioning problem,if you are using diffrent version of dll that is used in project in that case such error can take place.

here is one simple solution that worked for me in past,it will work for you if there is same problem. you can use " bindingRedirect " tag in web.config by defining old and new version of problematic dll. so that means it will ignore old version of dll reference and use newer one if found.and will not generate error.

here is the reference link. http://msdn.microsoft.com/en-us/library/eftw1fys%28v=vs.71%29.aspx

You need to use something like IKVM.Reflection,

http://weblog.ikvm.net/PermaLink.aspx?guid=d0dc2476-471b-45f3-96bf-a90bc2f5800b

Microsoft's reflection is tied to the hosted .NET Framework, so you cannot load an older version of the core libraries as wished.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM