为什么我的 App.Config 代码库无法帮助 .NET 定位我的程序集?
我有以下客户端应用程序及其相应的 config
文件:
namespace Chapter9
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.ExecuteAssembly("AssemblyPrivate.exe");
}
}
}
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<codeBase href="file://C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\AssemblyPrivate\bin\Debug\AssemblyPrivate.exe"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
AssemblyPrivate.exe
没有公钥,也不位于 GAC 中。 据我所知,运行时应该在客户端应用程序目录中查找程序集之前解析 app.config
文件。
未处理的异常(为了可读性而包装)是:
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集 '文件:///C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\Chapter9\bin\Debug\AssemblyPrivate.exe' 或其依赖项之一。 系统找不到指定的文件。
为什么它不起作用? 我需要使用动态绑定(不是静态)。
I have the following client application and its corresponding config
file:
namespace Chapter9
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.ExecuteAssembly("AssemblyPrivate.exe");
}
}
}
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<codeBase href="file://C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\AssemblyPrivate\bin\Debug\AssemblyPrivate.exe"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The AssemblyPrivate.exe
does not have a public key, nor is it located in the GAC. As far as I know, the runtime should parse the app.config
file before looking for an assembly in the client app directory.
The unhandled exception (wrapped for readability) is:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly
'file:///C:\Users\djpiter\Documents\Visual Studio 2008\Projects\70536\Chapter9\bin\Debug\AssemblyPrivate.exe'
or one of its dependencies. The system cannot find the file specified.
Why it is not working? I need to use dynamic binding (not static).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您现在可能自己解决了这个问题,所以仅供参考:
我相信您缺少“ assemblyIdentity”元素。 如果您将其附加指定到 codeBase 元素,它应该可以工作。
请参阅 http://msdn.microsoft.com /en-us/library/b0yt6ck0%28v=VS.100%29.aspx
You probably solved this problem on your own by now, so just for reference:
I believe you are missing an "assemblyIdentity" element. If you specify it additionally to the codeBase element, it should work.
See http://msdn.microsoft.com/en-us/library/b0yt6ck0%28v=VS.100%29.aspx
不要忽视“或其依赖项之一”。 您确定 AssemblyPrivate.exe 的所有依赖项都可用吗?
Don't overlook that "or one of its dependencies". Are you sure all AssemblyPrivate.exe's dependencies are available?