我有一个在集成v4.0应用程序池中的IIS 7.0中运行的网站.从今天开始,我在Windows事件日志中得到以下异常.该网站在线1个月,之前我从未遇到此例外.我在每小时的同一分钟得到例外,这有点奇怪.
一些可能的原因:
我有一个我创建的库,我动态加载.
_searchProvider = (ISearchProvider)Activator.CreateInstance("SolrSearchProvider", "SearchProviders.SolrSearchProvider.SolrSearchProvider").Unwrap();
Run Code Online (Sandbox Code Playgroud)
该库提到了SolrNet.
你知道问题可能是什么,或者如何进一步研究找到解决方案???
An unhandled exception occurred and the process was terminated.
Application ID: DefaultDomain
Process ID: 7192
Exception: System.Runtime.Serialization.SerializationException
Message: Unable to find assembly 'SolrNet, Version=0.4.0.1001, Culture=neutral, PublicKeyToken=bc21753e8aa334cb'.
StackTrace: at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at …Run Code Online (Sandbox Code Playgroud) 我的视觉工作室模板向导的gui出现时遇到了问题.我按照以下步骤操作:http://msdn.microsoft.com/en-us/library/ms185301.aspx
这是我做的:
1)使用以下文件生成C#类库(.dll):
UserInputForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace myprojectvstemplate
{
public partial class UserInputForm : Form
{
private string customMessage;
public UserInputForm()
{
InitializeComponent();
MessageBox.Show("here, calling ui");
}
public string get_CustomMessage()
{
return customMessage;
}
private void button1_Click(object sender, EventArgs e)
{
customMessage = textBox1.Text;
this.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
2)添加了一个用户输入表单,其中包含一个编辑框和一个代码为UserInputForm.cs的组合框
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TemplateWizard;
using System.Windows.Forms;
using EnvDTE;
namespace myprojectvstemplate
{
public …Run Code Online (Sandbox Code Playgroud) c# .net-assembly visual-studio visual-studio-templates visual-studio-2012
我在尝试从内存而不是从磁盘加载.NET程序集时遇到了一个令人困惑的问题.如果我编译程序集然后从磁盘加载它(使用LoadFile或LoadFrom),那么应用程序工作正常.
但是,如果我将已编译的程序集DLL文件作为嵌入式资源包含在项目中,然后使用Assembly.Load从资源流加载字节,那么随着应用程序继续运行,我会收到一系列随机错误.
这只是应用程序中八个程序集之一的问题 - 所有其他程序在磁盘或内存中都能正常工作.
谢谢您的帮助!
我有一个项目正在接收"类或命名空间''在类或命名空间中不存在''"错误.我在这里看到了很多解决方案,但我无法解决我的问题.
我有一个包含2个项目的解决方案,Web.Frameworks.Database和Web.Reports.OrderReporting.我试图在Reports.OrderReporting中引用Frameworks.Database项目.我还确认两个项目都在编译到同一个框架(.NET Framework 4.5)更新:我已经添加了对项目的引用(在Solution explorer中).
此时,Frameworks.Database项目中只有一个.cs文件,其中没有多少,它看起来像这样:
using System;
using System.Data;
using System.Web;
using System.Data.SqlClient;
namespace Web.Frameworks.Database
{
public class AccessDB : IHttpModule
{
/// <summary>
/// You will need to configure this module in the Web.config file of your
/// web and register it with IIS before being able to use it. For more information
/// see the following link: http://go.microsoft.com/?linkid=8101007
/// </summary>
#region IHttpModule Members
public void Dispose()
{
//clean-up code here.
}
public void Init(HttpApplication context)
{
// …Run Code Online (Sandbox Code Playgroud) 尝试在VS Post Build中合并多个程序集时遇到了问题:
ILMerge version 2.13.307.0
Copyright (C) Microsoft Corporation 2004-2006. All rights reserved.
ILMerge /out:Assembly.dll AssemblyA.dll AssemblyB.dll /targetplatform:v2,C:\Windows\Microsoft.NET\Framework\v3.5 /log:log.txt
Set platform to 'v2', using directory 'C:\Windows\Microsoft.NET\Framework\v3.5' for mscorlib.dll
An exception occurred during merging:
Unable to cast object of type 'System.Compiler.Class' to type 'System.Compiler.Struct'.
at System.Compiler.SystemTypes.Initialize(Boolean doNotLockFile, Boolean getDebugInfo, PostAssemblyLoadProcessor postAssemblyLoad)
at ILMerging.ILMerge.Merge()
at ILMerging.ILMerge.Main(String[] args)
Run Code Online (Sandbox Code Playgroud)
AssemblyA是当前项目输出$(TargetFileName),AssemblyB是引用的程序集.
奇怪的是,当我更改命令以使用.NET 4时,它可以工作:
ILMerge /out:Assembly.dll AssemblyA.dll AssemblyB.dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /log:log.txt
Run Code Online (Sandbox Code Playgroud)
由于我希望合并的程序集是版本3.5而不是4,如何让前一个命令工作或如何解决此错误?
我有一个第三方程序集,我想Internal在我的新C#项目中使用它的类.可能吗?
真的很感激任何一个例子
我的程序有一个pluginManager模块,它可以加载DLL文件并运行DLL的方法,但我需要先阅读DLL属性Assembly.LoadFile().我该怎么办?
我读了关于Assembly文档,他们读了属性之后Assembly.LoadFile(),你知道Assembly没有UnLoad()方法,所以我必须在LoadFile()之前读取属性

private void ImprotZip(string path)
{
/*
1?create tempDir, uppackage to tempDir
2?Load Plugin DLL, Load plugin dependent lib DLL
*/
string tempDirectory = CreateRuntimeDirectory(path);
string[] dllFiles = Directory.GetFiles(tempDirectory);
///Load DlL
foreach(string dll in dllFiles)
{
ImprotDll(dll, false);
}
string libPath = string.Format("{0}\\lib\\", tempDirectory);
if (!Directory.Exists(libPath))
return;
string[] dlls = Directory.GetFiles(libPath);
///Load plugin dependent lib DLL
foreach(string dll in dlls)
{
try
{
//filtering same DLL
//if(Dll.properties.AssemblyProduct != "something")
//continue;
Assembly.LoadFile(dll);
}
catch(Exception e)
{ …Run Code Online (Sandbox Code Playgroud) 我收到“投递装配失败,因为它被对象引用”错误。据我了解,我需要在删除该程序集之前删除所有引用到该程序集的功能。有什么通用的方法吗?
编辑:我没有提到一个重要的事情 - 加载我的程序集的应用程序实际上不在同一目录(与其他dll).在摆弄Fusion日志之后,我注意到加载的dll行为与我之前的想法不同.(是的,我应该先RTFM,对我感到羞耻)
C:\Test\appLoadingStuff.exeC:\Lib\Acme.Application.dllC:\Lib\Acme.Data.dll.NET正在探测应用程序库(除了GAC和东西;加载应用程序的目录是 - C:\Test\),并不关心dll存储加载的位置(其他目录).
在使用.NET框架时,我发现自己得到了一个ReflectionTypeLoadException例外:
System.TypeLoadException
无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.
无法从程序集'Acme.Data.Dao,Version = 1.1.0.4,Culture = neutral,PublicKeyToken = null'加载类型'Acme.Data.Foo'.":"Acme.Data.Foo
为简单起见,我有3个组件:
Acme.Application 我的主要装配Acme.Data 我的数据对象(由第一个引用)Acme.Data.Dao 我的数据访问对象(由第一个引用)还有另一个应用程序,实际上加载我的主程序集.所有.dll文件都在同一目录中.
正如您所料,类型Acme.Data.Foo是生活在组装中Acme.Data.尽管如此,.NET正试图在另一个程序集中找到它Acme.Data.Dao- 它失败了,因为类型不存在.
我无法弄清楚是什么让.NET在错误的程序集中寻找特定类型.在汇编时访问类型时会立即抛出异常:
System.Reflection.RuntimeAssembly assembly = Assembly.LoadFile("C:\Lib\Acme.Application.dll")
var types = assembly.GetTypes(); // -> explodes
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下方法检查引用的程序集
assembly.GetReferencedAssemblies()
Run Code Online (Sandbox Code Playgroud)
我可以在列表中清楚地看到我想要的装配.
没有程序集重定向(据我所知,这仅影响版本).程序集的版本是正确的.
我还应该寻找什么?
我疯了找它!
我在这篇文章中接近答案,但该包中没有DependencyContext.Default.