当 dll 添加到 GAC 时应用程序失败,否则还好
我有一个引用一些 .Net dll 的应用程序,用于在不同格式之间转换文件。如果我添加对 .dll 文件的引用,我的应用程序运行时不会出现问题。
但是,如果我将 dll 添加到 GAC 并从那里引用它,我的应用程序会由于解析错误而在运行时失败。 dll 的物理位置未更改。
我有几个通过环境变量访问的配置文件,这些文件用于解析输入文件。
任何想法可能是什么问题?
private static string FILE_CONFIGURATION = "configuration.xml";
string configurationPath = "c:\\temp\\CDXMLViewerDist\\" + FILE_CONFIGURATION;
System.Environment.SetEnvironmentVariable(translator.domains.XMLDomainConfiguration.FILE_CONFIGURATION_PATH, configurationPath);
System.Environment.SetEnvironmentVariable(translator.domains.XMLDomainConfiguration.DOMAIN_CONFIGURATION_PROPERTY_KEY, typeof(XMLDomainConfiguration).FullName);
String strPath = "C:\\temp\\out.cdxml";
CDXMLReader reader = new CDXMLReader();
reader.Read(strPath); // Runs fine if reference dll as file, throws exception if via GAC
I have an application which references some .Net dlls and is used to convert a file between different formats. If I add a reference to the .dll file, my application runs without problem.
However, if I add the dll to the GAC, and reference it from there, my application fails during run time, due to a parsing error. The physical location of the dlls are unchanged.
I have several configuration files which are accessed via environment variables, and these are used to parse input files.
Any ideas what might be the problem?
private static string FILE_CONFIGURATION = "configuration.xml";
string configurationPath = "c:\\temp\\CDXMLViewerDist\\" + FILE_CONFIGURATION;
System.Environment.SetEnvironmentVariable(translator.domains.XMLDomainConfiguration.FILE_CONFIGURATION_PATH, configurationPath);
System.Environment.SetEnvironmentVariable(translator.domains.XMLDomainConfiguration.DOMAIN_CONFIGURATION_PROPERTY_KEY, typeof(XMLDomainConfiguration).FullName);
String strPath = "C:\\temp\\out.cdxml";
CDXMLReader reader = new CDXMLReader();
reader.Read(strPath); // Runs fine if reference dll as file, throws exception if via GAC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题是由于尝试使用 object
o = Activator.CreateInstance( assemblyName, fullQualifiedTypeName);
实例化对象所致。通过 GAC 访问时,我需要使用完全限定的程序集名称,而不仅仅是程序集名称,例如
“AssemblyName, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=abcdef1234567890”
The problem was due to an attempt to instantiate an object using
object o = Activator.CreateInstance(assemblyName, fullyQualifiedTypeName);
When accessing via the GAC, I needed to use a fully qualified assembly name rather than just the assembly name e.g.
"AssemblyName, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=abcdef1234567890"