日期:2014-05-19  浏览次数:20849 次

Assembly的强名称问题
1.用sn.exe生成了一个snk文件,并得到它的publicTokenKey=4e42cc2fb60e7d4b(绝对无误会)
2.建立了一个C#   DLL项目,并在项目配置中把上面的snk文件选择给了它
3.在另外一个C#的控制台项目中动态加载这个DLL,可是抛出异常
代码如下:
Assembly.Load( "E:\\Test\\AppDomain\\TestDll\\bin\\Debug\\TestDll.dll,Version=1.0.0.0,Culture=neutral,PublicKeyToken=4e42cc2fb60e7d4b ");

异常提示如下:

Unhandled   Exception:   System.IO.FileLoadException:   Could   not   load   file   or   assembl
y   'E:\\Test\\AppDomain\\TestDll\\bin\\Debug\\TestDll.dll\,Version\=1.0.0.0\,Cult
ure\=neutral\,PublicKeyToken\=4e42cc2fb60e7d4b '   or   one   of   its   dependencies.   The
given   assembly   name   or   codebase   was   invalid.   (Exception   from   HRESULT:   0x80131047
)
File   name:   'E:\\Test\\AppDomain\\TestDll\\bin\\Debug\\TestDll.dll\,Version\=1.0.
0.0\,Culture\=neutral\,PublicKeyToken\=4e42cc2fb60e7d4b '
      at   System.Reflection.AssemblyName.nInit(Assembly&   assembly,   Boolean   forIntros
pection,   Boolean   raiseResolveEvent)
      at   System.Reflection.Assembly.InternalLoad(String   assemblyString,   Evidence   as
semblySecurity,   StackCrawlMark&   stackMark,   Boolean   forIntrospection)
      at   System.Reflection.Assembly.Load(String   assemblyString)
      at   AppDomainTest.Program.Main(String[]   args)   in   E:\Test\AppDomain\AppDomain\P
rogram.cs:line   23

------解决方案--------------------
up