我只是想知道如果我要在Web应用程序中加载相同的汇编字节两次会发生什么.
例如,我有这个代码
byte[] assem = System.IO.File.ReadAllBytes(appRoot + "/Plugins/Plugin.dll");
var loadedAssem = Assembly.Load(assem);
var plugin = loadedAssem.CreateInstance("Plugin.ThePlugin") as IPlugin;
Run Code Online (Sandbox Code Playgroud)
我运行此代码,并在第一个请求我假设它将程序集加载到ram(或http运行时appdomain?)然后我可以创建其中的任何内容的实例.
如果我再次运行此代码,请在第二个请求上说第一个请求上的程序集会发生什么?
ram还会存在吗?如果是这样,它如何区分两个组件?还是会覆盖以前的声明类?
这是我的理解,就像我在PHP中所做的那样,它不仅仅是"require_once"的情况.
昨天我的项目运行顺利,但今天我遇到了一个错误.以下是详细信息:
无法加载文件或程序集'file:/// C:\ WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\parktms\c8392404\1ba3bab5\App_Web_login.aspx.6cc23264.lmj8uym6.dll'或其中一个依赖项.句柄无效.(来自HRESULT的异常:0x80070006(E_HANDLE))描述:在执行当前Web请求期间发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
例外细节:
System.IO.FileLoadException:无法加载文件或程序集'file:/// C:\ WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\parktms\c8392404\1ba3bab5\App_Web_login.aspx.6cc23264 .lmj8uym6.dll'或其依赖项之一.句柄无效.(HRESULT异常:0x80070006(E_HANDLE))
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[FileLoadException:无法加载文件或程序集'file:/// C:\ WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\parktms\c8392404\1ba3bab5\App_Web_login.aspx.6cc23264.lmj8uym6. dll'或其依赖项之一.句柄无效.(来自HRESULT的异常:0x80070006(E_HANDLE))] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)+0 System.Reflection.RuntimeAssembly .nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RunCAslmbly locationHint,StackCrawlMark&stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)+39 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,Evidence assemblySecurity,StackCrawlMark&stackMark,Boolean forIntrospection,Boolean suppressSecurityChecks)+132 System.Reflection.Assembly.Load(AssemblyName assemblyRef,Evidence assemblySecurity)+28 System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()+93 System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results)+65 System.Web.Compilation.TemplateControlBuildProvider.CreateBuildResult(CompilerResults results)+36 System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results)+16 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)+8967378 System.Web.Compilation .BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,Boolean noBuild,Boolean allowCrossApp,Boolean allowBuildInPrecompile,Boolean throwIfNotFound,Boolean ensureIsUpToDate)+320 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context,VirtualPath virtualPath,Boolean noBuild,Boolean allowCrossApp,Boolean allowBuildInPrecompile, Boolean throwIfNotFound,Boolean ensureIsUpToDate)+111 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext context,Boolean allowCrossApp,Boolean throwIfNotFound)+125 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,Type …
我得到的反馈:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools>gacutil.
exe /i "C:\Users\wherever\ClassLibrary1.dll"
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Assembly successfully added to the cache
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools>
Run Code Online (Sandbox Code Playgroud)
但它不是在寻找内容
gacutil.exe /l | clip
Run Code Online (Sandbox Code Playgroud)
它不在/ Windows /程序集中
我正在使用.net 4.
我尝试构建我的asp.net应用程序时遇到构建错误.错误是:
"MediCare.Framework.Authentication.IUserAuthenticate"类型在未引用的程序集中定义.您必须添加对程序集'MediCare.Framework,Version = 1.0.1.95,Culture = neutral,PublicKeyToken = 1999fa3c42b9'的引用.
我可以在库中看到引用文件夹中的类.我该如何调试此问题?
我的目的是将references文件夹指向库源代码的bin目录(因为pdb文件在那里被lcoated,并且对库的任何更新都将反映在应用程序中).但是,当我将references文件夹指向源代码的bin目录时,我收到上面的错误消息.
更新该应用程序最初是在VS 2008中开发的,我在2010年对其进行修改.如果我使用VS 2010(2.0框架位置或4.0框架位置),我认为我对GAC程序集的位置感到困惑?.NET 4.0有一个新的GAC,为什么?
更新(06-26-2012)
GAC中的文件("C:\ Windows\assembly \")已被删除.但是这个错误仍然存在.
<Component Guid="7F7333F5-F9ED-4712-8D1B-58AAC71790CB" Id="MyComponent">
<File Name="MyDll.dll" KeyPath="yes" Vital="yes"
Id="MyDLL_GAC" Assembly=".net" Source="$(var.COMTRACERDIR)\MyDll.dll">
</File>
</Component>
当我使用它来制作带有wix的*.msi时,我发现dll将安装在路径"C:\ Windows\Microsoft.NET\assembly\GAC_32 ..."而不是"C:\ Windows\assembly"中\ GAC_32" .
Version.NET中的类表示版本号由两到四个组件组成.AssemblyInfo文件为AssemblyVersion和AssemblyFileVersionfileds 指定以下格式:
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
Run Code Online (Sandbox Code Playgroud)
目前还不清楚如果Build Number和Revision这里是必需的,因为它们不是在需要的Version类.他们需要吗?换句话说,这是合法的吗?
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0")]
Run Code Online (Sandbox Code Playgroud)
或者这需要表示如下?
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Run Code Online (Sandbox Code Playgroud) 我想创建一个Excel程序集的引用并使用此代码:
[Test]
public void ExcelTest()
{
Assembly current = this.GetType().Assembly;
Assembly excel = typeof(Microsoft.Office.Interop.Excel.Workbook).Assembly;
Assert.AreEqual(current.FullName, excel.FullName); // Why is excel the same as current assembly?
}
[Test]
public void MscorlibTest()
{
Assembly mscorlib = typeof(string).Assembly;
Assert.IsTrue(mscorlib.FullName.StartsWith("mscorlib"));
Assembly current = this.GetType().Assembly;
Assert.AreNotEqual(mscorlib.FullName,current.FullName); // As expected
}
Run Code Online (Sandbox Code Playgroud)
为什么excel和我现在的装配一样?
获得Excel程序集的好方法是什么?
在阅读文档时无法找到我的愚蠢
所以我试图准确理解.NET程序集何时加载到.NET进程中.我读了这篇博客文章,它很好地解释了一些事情并证实了我认为已经知道的很多东西,但它也提出了一个我认为我有点误解的观点.
在代码中首次引用时,从属程序集只是及时加载
我认为这意味着当第一次调用程序集时,然后将程序集加载到程序中.因此,如果我有一个类似于下面示例的程序,其中RasDialer实例化类的行将永远不会被调用 - 我相信DotRas程序集永远不会被加载到进程中,我肯定是错的.
但是,如果代码在我注释掉的部分中确实无法访问 - 那么程序集将永远不会加载,但似乎如果有机会则会加载程序集.
这是我的小测试应用程序:
static void Main(string[] args)
{
Console.WriteLine("Before");
var dictionary = new Dictionary<int, string>();
PrintAssemblies(); // <- DotRas is loaded here for null check variant
if (dictionary == null)
{
// This line will never execute, but it does not matter
var dialer = new RasDialer();
}
// DotRas will not be loaded if I uncomment this and comment
// out the other if statement …Run Code Online (Sandbox Code Playgroud) 我有一个包含3个项目的解决方案:1)GUI可执行文件2)包含公共API和公共接口的类库3)实现上述接口的类的类库
我正在尝试在API中实现资源加载器,这样当GUI调用方法时,API.Foo()我会遍历特定文件夹(位于:.\ resources)中 的每个程序集,其中包含我编译的程序集的副本(#3) .然后我想将资源添加到列表中并使用此列表来调用作为接口一部分的函数(每个资源都实现)
所以我做的是:
private List<IResource> m_resources;
public void Foo()
{
string resourceDir = Directory.GetCurrentDirectory() + @"\Resources";
m_resources= new List<IResource>();
foreach (var dllFile in Directory.EnumerateFiles(resourceDir))
{
IResource dllInstance;
if (TryLoadingDLL(Path.Combine(resourceDir, dllFile), out dllInstance))
{
resources.Add(dllInstance);
}
}
}
private static bool TryLoadingDLL(string dllFullPath, out IResource instanceOfDll)
{
instanceOfDll = null;
try
{
Assembly assembly = Assembly.LoadFrom(dllFullPath);
Assembly IResourceAssambly = Assembly.LoadFrom(@"C:\MyProject\MyAPI.dll");
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
var interfaces = type.GetInterfaces(); …Run Code Online (Sandbox Code Playgroud) 
我只在设计时才收到此错误.
在运行时一切正常.I-Synergy.Resources类库绝对没有错.
我已经集中搜索了这个错误但没有解决方案.
(已经尝试过:
)
.net-assembly ×10
c# ×5
.net ×4
asp.net ×2
com ×2
gac ×2
reflection ×2
assemblies ×1
assemblyinfo ×1
design-time ×1
dll ×1
jit ×1
plugins ×1
versioning ×1
wix ×1
wpf ×1
xaml ×1