binding - Can't get .NET Policy DLL to redirect application to newer assembly -
binding - Can't get .NET Policy DLL to redirect application to newer assembly -
my background in technical back upwards had resulted in me putting far much info in post, leading nobody beingness interested in reading it, imho, more info improve less.
there basic , fundamental assembly binding , redirection i'm missing. i'm trying create policy dll redirect applications have compiled against older version of assembly newest version. nil seems work. i've outlined steps take below. i'm not using visual studio, command line tools included .net framework , windows sdk. can tell me why, in step eleven, when run application compiled against v1.0.0 version of assembly, application not redirected towards v2.0.0 assembly registered in gac?
as follow along did, you'll have take note of directory i've executed commands in.
i more happy rtfm answer, if you'd kind point tfm i'm supposed read.
thanks in advance, reg
step 1 : create key pair name assembly.c:\stackexchangetest> sn -k stacktest.snk microsoft (r) .net framework strong name utility version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. key pair written stacktest.snk c:\stackexchangetest> sn -p stacktest.snk publicstacktest.snk microsoft (r) .net framework strong name utility version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. public key written publicstacktest.snk c:\stackexchangetest> sn -tp publicstacktest.snk microsoft (r) .net framework strong name utility version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. public key 002400000480000094000000060200000024000052534131000400000100010079ba0ab991ceda d7ba4a767d55889a6cd0eafc9bc15c394620b61c02f4c1112dd9e348cbb4826775c72164ac8552 f9b751b1a1dd71874c04b24221f00f4ee8c2971f3ac8b6b381b26d39cbd3347e773bf08e9af838 6d7f317592951a4985e2c187288d037d5af2f62cce2e4dc700d0d00feb4c095df5d12c9a0908dc 8606cdad public key token 6dfd37060fccec62
step 2 : create assembly version v1.0.0 c:\stackexchangetest\1.0.0> type stacktest.cs using system; namespace stack.exchange.rdomarat { public class stacktest { public static string getversion() { return( "1.0.0" ); } } } c:\stackexchangetest\1.0.0> type assemblyinfo.cs using system.reflection; using system.runtime.compilerservices; using system.runtime.interopservices; [assembly: assemblytitle("stack.exchange.rdomarat")] [assembly: assemblydescription("")] [assembly: assemblyconfiguration("")] [assembly: assemblycompany("stackexchange")] [assembly: assemblyproduct("rdomarat")] [assembly: assemblycopyright("copyright 2012")] [assembly: assemblytrademark("rdomarat")] [assembly: assemblyculture("")] [assembly: comvisible(false)] [assembly: guid("a3d17815-97f5-4e56-803c-06f652a23369")] [assembly: assemblyversion( "1.0.0" )] c:\stackexchangetest\1.0.0> csc /out:stack.exchange.rdomarat.dll /keyfile:../stacktest.snk /debug /w:4 /t:library assemblyinfo.cs stacktest.cs microsoft (r) visual c# 2008 compiler version 3.5.30729.5420 microsoft (r) .net framework version 3.5 copyright (c) microsoft corporation. rights reserved.
step 3 : create policy dll v1.0.0 assembly c:\stackexchangetest\1.0.0> type stack.exchange.rdomarat.config <configuration> <runtime> <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentassembly> <assemblyidentity name="stack.exchange.rdomarat" publickeytoken="6dfd37060fccec62" culture=neutral /> <bindingredirect oldversion="1.0.0-1.0.0" newversion="1.0.0" /> </dependentassembly> </assemblybinding> </runtime> </configuration> c:\stackexchangetest\1.0.0> al.exe /version:1.0.0 /link:stack.exchange.rdomarat.config /out:policy.1.0.stack.exchange.rdomarat.dll /keyfile:../stacktest.snk /description:"policy file" /title:"policy file" /company:"stackexchange" /copyright:"copyright 2012" /trademark:"rdomarat" /product:"rdomarat" microsoft (r) assembly linker version 9.0.30729.1 copyright (c) microsoft corporation. rights reserved.
step 4 : register 2 assemblies gac c:\stackexchangetest\1.0.0> gacutil -u stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. no assemblies found matching: stack.exchange.rdomarat number of assemblies uninstalled = 0 number of failures = 0 c:\stackexchangetest\1.0.0> gacutil -u policy.1.0.stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. no assemblies found matching: policy.1.0.stack.exchange.rdomarat number of assemblies uninstalled = 0 number of failures = 0 c:\stackexchangetest\1.0.0> gacutil -i stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache c:\stackexchangetest\1.0.0> gacutil -i policy.1.0.stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache
step 5 : create application uses new v1.0.0 assembly c:\stackexchangetest\stackapp\1.0.0> type stackapp.cs using system; using stack.exchange.rdomarat; public class stackapp { public static void main() { string s1; s1 = stacktest.getversion(); console.writeline("hello " + s1); } } c:\stackexchangetest\stackapp\1.0.0> csc /out:stackapp.exe /target:exe /reference:..\..\1.0.0\stack.exchange.rdomarat.dll stackapp.cs microsoft (r) visual c# 2008 compiler version 3.5.30729.5420 microsoft (r) .net framework version 3.5 copyright (c) microsoft corporation. rights reserved. c:\stackexchangetest\stackapp\1.0.0> stackapp hello 1.0.0
step 6 : create v2.0.0 stack.exchange.rdomarat.dll assembly c:\stackexchangetest\2.0.0> type stacktest.cs using system; namespace stack.exchange.rdomarat { public class stacktest { public static string getversion() { return( "2.0.0" ); } } } c:\stackexchangetest\2.0.0> type assemblyinfo.cs using system.reflection; using system.runtime.compilerservices; using system.runtime.interopservices; [assembly: assemblytitle("stack.exchange.rdomarat")] [assembly: assemblydescription("")] [assembly: assemblyconfiguration("")] [assembly: assemblycompany("stackexchange")] [assembly: assemblyproduct("rdomarat")] [assembly: assemblycopyright("copyright 2012")] [assembly: assemblytrademark("rdomarat")] [assembly: assemblyculture("")] [assembly: comvisible(false)] [assembly: guid("a3d17815-97f5-4e56-803c-06f652a23369")] [assembly: assemblyversion( "2.0.0" )] c:\stackexchangetest\2.0.0> csc /out:stack.exchange.rdomarat.dll /keyfile:../stacktest.snk /debug /w:4 /t:library assemblyinfo.cs stacktest.cs microsoft (r) visual c# 2008 compiler version 3.5.30729.5420 microsoft (r) .net framework version 3.5 copyright (c) microsoft corporation. rights reserved.
step 7 : create policy dll v2.0.0 assembly c:\stackexchangetest\2.0.0> type stack.exchange.rdomarat.config <configuration> <runtime> <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentassembly> <assemblyidentity name="stack.exchange.rdomarat" publickeytoken="6dfd37060fccec62" culture=neutral /> <bindingredirect oldversion="1.0.0-2.0.0" newversion="2.0.0" /> </dependentassembly> </assemblybinding> </runtime> </configuration> c:\stackexchangetest\2.0.0> al.exe /version:2.0.0 /link:stack.exchange.rdomarat.config /out:policy.2.0.stack.exchange.rdomarat.dll /keyfile:../stacktest.snk /description:"policy file" /title:"policy file" /company:"stackexchange" /copyright:"copyright 2012" /trademark:"rdomarat" /product:"rdomarat" microsoft (r) assembly linker version 9.0.30729.1 copyright (c) microsoft corporation. rights reserved.
step 8 : register 2 v2.0.0 assemblies gac c:\stackexchangetest\2.0.0> gacutil -u policy.2.0.stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. no assemblies found matching: policy.2.0.stack.exchange.rdomarat number of assemblies uninstalled = 0 number of failures = 0 c:\stackexchangetest\2.0.0> gacutil -i stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache c:\stackexchangetest\2.0.0> gacutil -i policy.2.0.stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache
step 9 : create application uses new v2.0.0 assembly c:\stackexchangetest\stackapp\2.0.0> type stackapp.cs using system; using stack.exchange.rdomarat; public class stackapp { public static void main() { string s1; s1 = stacktest.getversion(); console.writeline("hello " + s1); } } c:\stackexchangetest\stackapp\2.0.0> csc /out:stackapp.exe /target:exe /reference:..\..\2.0.0\stack.exchange.rdomarat.dll stackapp.cs microsoft (r) visual c# 2008 compiler version 3.5.30729.5420 microsoft (r) .net framework version 3.5 copyright (c) microsoft corporation. rights reserved. c:\stackexchangetest\stackapp\2.0.0> stackapp.exe hello 2.0.0
step 10 : unregister gac, , confirm neither app works c:\stackexchangetest\stackapp\2.0.0> gacutil -u policy.2.0.stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly: policy.2.0.stack.exchange.rdomarat, version=2.0.0.0, culture=neutral,publickeytoken=6dfd37060fccec62, processorarchitecture=msil uninstalled: policy.2.0.stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil number of assemblies uninstalled = 1 number of failures = 0 c:\stackexchangetest\stackapp\2.0.0> gacutil -u policy.1.0.stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly: policy.1.0.stack.exchange.rdomarat, version=1.0.0.0, culture=neutral,publickeytoken=6dfd37060fccec62, processorarchitecture=msil uninstalled: policy.1.0.stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil number of assemblies uninstalled = 1 number of failures = 0 c:\stackexchangetest\stackapp\2.0.0> gacutil -u stack.exchange.rdomarat microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly: stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil uninstalled: stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil assembly: stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil uninstalled: stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62, processorarchitecture=msil number of assemblies uninstalled = 2 number of failures = 0 c:\stackexchangetest\stackapp\1.0.0> stackapp.exe unhandled exception: system.io.filenotfoundexception: not load file or assembly 'stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' or 1 of dependencies. scheme cannot find file specified. file name: 'stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' @ stackapp.main() assembly manager loaded from: c:\windows\microsoft.net\framework64\v2.0.50727\mscorwks.dll running under executable c:\stackexchangetest\stackapp\1.0.0\stackapp.exe --- detailed error log follows. === pre-bind state info === log: user = sybase\rdomarat log: displayname = stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 (fully-specified) log: appbase = file:///c:/users/rdomarat/documents/issues/111205_mlclient_policy/stackexchangetest/stackapp/1.0.0/ log: initial privatepath = null calling assembly : stackapp, version=0.0.0.0, culture=neutral, publickeytoken=null. === log: bind starts in default load context. log: no application configuration file found. log: using machine configuration file c:\windows\microsoft.net\framework64\v2.0.50727\config\machine.config. log: post-policy reference: stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 log: same bind seen before, , failed hr = 0x80070002. c:\stackexchangetest\stackapp\2.0.0> stackapp.exe unhandled exception: system.io.filenotfoundexception: not load file or assembly 'stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' or 1 of dependencies. scheme cannot find file specified. file name: 'stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' @ stackapp.main() assembly manager loaded from: c:\windows\microsoft.net\framework64\v2.0.50727\mscorwks.dll running under executable c:\stackexchangetest\stackapp\2.0.0\stackapp.exe --- detailed error log follows. === pre-bind state info === log: user = sybase\rdomarat log: displayname = stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 (fully-specified) log: appbase = file:///c:/users/rdomarat/documents/issues/111205_mlclient_policy/stackexchangetest/stackapp/2.0.0/ log: initial privatepath = null calling assembly : stackapp, version=0.0.0.0, culture=neutral, publickeytoken=null. === log: bind starts in default load context. log: no application configuration file found. log: using machine configuration file c:\windows\microsoft.net\framework64\v2.0.50727\config\machine.config. log: post-policy reference: stack.exchange.rdomarat, version=2.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 log: same bind seen before, , failed hr = 0x80070002.
step 11 : re-register v2.0.0 assembly, both application should work c:\stackexchangetest\2.0.0> gacutil -i stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache c:\stackexchangetest\2.0.0> gacutil -i policy.2.0.stack.exchange.rdomarat.dll microsoft (r) .net global assembly cache utility. version 3.5.30729.1 copyright (c) microsoft corporation. rights reserved. assembly added cache c:\stackexchangetest\stackapp\2.0.0> stackapp.exe hello 2.0.0 c:\stackexchangetest\stackapp\1.0.0> stackapp.exe unhandled exception: system.io.filenotfoundexception: not load file or assembly 'stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' or 1 of dependencies. scheme cannot find file specified. file name: 'stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62' @ stackapp.main() assembly manager loaded from: c:\windows\microsoft.net\framework64\v2.0.50727\mscorwks.dll running under executable c:\stackexchangetest\stackapp\1.0.0\stackapp.exe --- detailed error log follows. === pre-bind state info === log: user = sybase\rdomarat log: displayname = stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 (fully-specified) log: appbase = file:///c:/users/rdomarat/documents/issues/111205_mlclient_policy/stackexchangetest/stackapp/1.0.0/ log: initial privatepath = null calling assembly : stackapp, version=0.0.0.0, culture=neutral, publickeytoken=null. === log: bind starts in default load context. log: no application configuration file found. log: using machine configuration file c:\windows\microsoft.net\framework64\v2.0.50727\config\machine.config. log: post-policy reference: stack.exchange.rdomarat, version=1.0.0.0, culture=neutral, publickeytoken=6dfd37060fccec62 log: same bind seen before, , failed hr = 0x80070002.
turns out whole problem day 1 lack of double quotes around :
culture=neutral
i alter .config file read
culture="neutral"
and worked charm. error in assembly binding debug outlog log indicated parse error in xml config file have been handy, , might have saved me 2 days. oh well.
.net binding gac policyfiles
Comments
Post a Comment