[英]C#: How to load assembly from GAC?
I have "mycomp.myassembly.dll" in GAC but Load and LoadFrom throws file not found exception and LoadWithPartialName returns null. 我在GAC中有“mycomp.myassembly.dll”但Load和LoadFrom会抛出找不到文件的异常,而LoadWithPartialName则返回null。 I'm doing the following: 我正在做以下事情:
AssemblyName name = new AssemblyName();
name.Name = "mycomp.myassembly.dll";
Assembly assembly = Assembly.Load(name);
fails with FileNotFound for mycomp.myassembly.dll file, and 用于mycomp.myassembly.dll文件的FileNotFound失败,并且
Assembly assembly = Assembly.Load("mycomp.myassembly.dll");
fails with exactly the same message. 完全相同的消息失败了。
I double checked that assembly is in GAC (and even did gacutil /if for it again) and it does work in all other cases, I just unable to load it myself. 我仔细检查了汇编是否在GAC中(甚至再次使用gacutil / if)并且它在所有其他情况下都有效,我只是无法自己加载它。
What am I doing wrong here? 我在这做错了什么? Do I miss something? 我错过了什么吗?
Have you tried using the fully qualified assembly name? 您是否尝试过使用完全限定的程序集名称? (eg "ycomp.myassembly.dll, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
) (例如"ycomp.myassembly.dll, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
)
try simply loading with the full name 尝试使用全名加载
// You must supply a valid fully qualified assembly name.
Assembly SampleAssembly = Assembly.Load
("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
I can usually load without the version, culture and public key. 我通常可以加载没有版本,文化和公钥。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.