system.reflection - Issue with reflection in msbuild, devenv is good -



system.reflection - Issue with reflection in msbuild, devenv is good -

i have gone through questions related , not find issue , hence, asking question.

i have buildtask (added afterbuild target), validate types names. these type names qualified type names silverlight projects beingness build.

to resolve these type names, utilize type.reflectiononlygettype(). load dependent assemblies handle appdomain.currentdomain.reflectiononlyassemblyresolve event load project specific assemblies project output path , silverlight base of operations assemblies silverlight installation path using assembly.reflectiononlyloadfrom(filepath).

this works fine, when build projects in vs2010, fails when build msbuild i.e. c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe "c:\root\branches\x.x.x\clients.sln" /t:rebuild /p:configuration=debug "/p:platform=any cpu" /v:quiet /maxcpucount:1

while building msbuild, reflectiononlyassemblyresolve event fired "system, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e" , loaded silverlight installation path. but, probing trying scheme assembly in "c:/windows/microsoft.net/framework/v4.0.30319/system.dll", fail major version wont match.

following stripped version of code, specific problem:

public class validatetypetask : task { public override bool execute() { initialize(); list<string> typenames = gettypes(); foreach (var typename in typenames) { var isresolved = isresolvable(typename); if (!isresolved) { homecoming false; } } cleanup(); homecoming true; } private void initialize() { appdomain.currentdomain.reflectiononlyassemblyresolve += new resolveeventhandler(currentdomain_reflectiononlyassemblyresolve); } assembly currentdomain_reflectiononlyassemblyresolve(object sender, resolveeventargs args) { assembly loadedassembly = null; exception loadedexception = null; seek { loadedassembly = assembly.reflectiononlyload(args.name);//this fail } grab (exception ex) { loadedexception = ex; } if (loadedassembly != null) { homecoming loadedassembly; } string assemblypath = string.empty; var assemblyname = new assemblyname(args.name); if (args.name.startswith("system")) { assemblypath = @"c:\program files\reference assemblies\microsoft\framework\silverlight\v4.0"; } else { assemblypath = @"c:\root\branches\x.x.x\bin\debug"; } assemblypath = string.format(@"{0}\{1}.dll", assemblypath, assemblyname.name); if (file.exists(assemblypath)) { loadedassembly = assembly.reflectiononlyloadfrom(assemblypath); } if (loadedassembly == null) { throw loadedexception; } homecoming loadedassembly; } private void cleanup() { appdomain.currentdomain.reflectiononlyassemblyresolve -= new resolveeventhandler(currentdomain_reflectiononlyassemblyresolve); } private list<string> gettypes() { homecoming new list<string>(); } private bool isresolvable(string typename) { type resolvedtype = null; seek { resolvedtype = type.reflectiononlygettype(typename, true, true); } grab (exception ex) { } if (resolvedtype != null) { homecoming true; } homecoming false; } }

the exception follows:

system.io.fileloadexception: not load file or assembly 'system, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e' or 1 of dependencies. located assembly's manifest definition not match assembly reference. (exception hresult: 0x80131040) file name: 'system, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e' @ system.runtimetypehandle.gettypebyname(string name, boolean throwonerror, boolean ignorecase, boolean reflectiononly, stackcrawlmarkhandle stackmark, boolean loadtypefrompartialname, objecthandleonstack type) @ system.runtimetypehandle.gettypebyname(string name, boolean throwonerror, boolean ignorecase, boolean reflectiononly, stackcrawlmark& stackmark, boolean loadtypefrompartialname) @ system.runtimetype.gettype(string typename, boolean throwonerror, boolean ignorecase, boolean reflectiononly, stackcrawlmark& stackmark) @ system.type.reflectiononlygettype(string typename, boolean throwifnotfound, boolean ignorecase) @ in c:\root\x.xx.x\buildtasks\validatetypestask.cs line xxx assembly manager loaded from: c:\windows\microsoft.net\framework\v4.0.30319\clr.dll running under executable c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe --- detailed error log follows. === pre-bind state info === log: user = domain\username log: displayname = system, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e (fully-specified) log: appbase = file:///c:/windows/microsoft.net/framework/v4.0.30319/ log: initial privatepath = null calling assembly : (unknown). === log: inspection bind. log: using application configuration file: c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe.config log: using host configuration file: log: using machine configuration file c:\windows\microsoft.net\framework\v4.0.30319\config\machine.config. log: attempting download of new url file:///c:/windows/microsoft.net/framework/v4.0.30319/system.dll. wrn: comparing assembly name resulted in mismatch: major version err: failed finish setup of assembly (hr = 0x80131040). probing terminated.

i have tried including silverlight assemblies path assemblysearchpaths project property allow part of probing urls , still same.

i sure not reply problem posted above. but, how resolved it.

i had gone through forums , documentation , found basic difference between devenv , msbuild. when building msbuild assembly resolution happens in strict manner in devenv.

also, had gone through difference between assembly.loadfrom , assembly.reflectiononlyloadfrom. assembly.refelectiononlyloadfrom considers file name , not check on version, etc., msbuild loading system.dll .net 4.0 stack has load system.dll silverlight installation path.

with these in mind, tried load assemblies using assembly.loadfrom , used type.gettype resolve types. time, ran stackoverflowexception assemblyresolve event triggered loaded assemblies repeatedly.

this when thought of loading assemblies separate appdomain can unload loaded assemblies. found this article useful , followed similar pattern solve issue.

though have solved issue on hand, not want gain points answer. still sense have not provided reply issue msbuild.

hope might helpful others.

msbuild system.reflection

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -