当我在我的功能中没有EventReceivers时,项目构建和部署,并在我这样做时失败.我不完全确定FileNotFoundException指的是哪个文件
视觉工作室给出错误
Error 1 Error occurred in deployment step 'Activate Features': Failed to load receiver assembly "Decisions.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d09acb153961cfd" for feature "Decisions.Features_DeployDecisionCommittee" (ID: 779492d8-f053-45ce-8340-5fa6d7f87a90).: System.IO.FileNotFoundException: Could not load file or assembly 'Decisions.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d09acb153961cfd' or one of its dependencies. The system cannot find thefile specified.
File name: 'Decisions.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8d09acb153961cfd'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& …
Run Code Online (Sandbox Code Playgroud) 我在GAC中注册了一个DLL.我可以看到在路径中的DLL:c:\windows\asssembly
; 我想这意味着DLL正确注册.
但是,如果我必须在我的应用程序中使用DLL,我仍然需要单击"添加引用"并从上面的路径添加.
那么,如果我仍然需要再次添加引用,那么GAC的用途是什么?
我注意到我的系统上有关全局程序集缓存(GAC)的一些奇怪行为.我感兴趣的程序集是log4net Version = 1.2.11.0
输出gacutil /l "log4net"
是:
C:\ Windows\system32> gacutil/l"log4net"Microsoft(R).NET全局程序集缓存实用程序.版本4.0.30319.1版权所有(c)Microsoft Corporation.版权所有.
全局程序集缓存包含以下程序集:
log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821,processorArchitecture = MSIL
log4net,Version = 1.2.11.0,Culture = neutral,PublicKeyToken = 669e0ddf0bb1aa2a,processorArchitecture = MSIL物品数量= 2
但是,通过资源管理器shell(重新启动之前和之后)查看GAC只显示一个版本:
由于我的应用程序无法解析程序集,但是当我将它放入应用程序库(bin文件夹)时工作正常,这一点更加复杂.根据这篇文章,GAC将在应用程序基础之前进行探测- 这将指向程序集不在GAC中.
log4net Version=1.2.11.0
GAC 也是如此?如果是这样,为什么我的应用程序找不到它?
情况如下:
我有在.NET 2中编译的DLL,该DLL在全局程序集缓存中。我有这样的myDLL.dll.config
文件:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myDLL" publicKeyToken="c426c33bab532523" />
<bindingRedirect oldVersion="1.2.2.0-1.2.2.22" newVersion="1.2.2.23" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后,我使用程序集链接器创建策略文件:
al /link:myDLL.dll.config /out:policy.1.2.myDLL.dll /keyfile:myDLL.snk
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用以下方式将策略文件加载到全局程序集缓存中时
gacutil -i policy.1.2.myDLL.dll
Run Code Online (Sandbox Code Playgroud)
我得到错误:
Failure adding assembly to the cache: This assembly is built by a
runtime newer than the currently loaded runtime and cannot be loaded.
Run Code Online (Sandbox Code Playgroud)
.NET Global Assembly Cache Utility的版本为2.0.50727.42,但是我通过创建新的C#.NET 2控制台项目并执行以下命令在构建环境中检查了该版本:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ …
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
Register(Assembly.GetExecutingAssembly()).Location);
private void Register(String assemblyName)
{
System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("D://gacutil.exe", string.Format("/i {0}", assemblyName));
processStartInfo.UseShellExecute = false;
System.Diagnostics.Process process= System.Diagnostics.Process.Start(processStartInfo);
process.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)
如何将DLL添加到程序集文件夹?