我使用 Unity 来解析我的实例。包括WCF服务。
但是我发现了一个棘手的问题。 我将 WCF 程序部署到 IIS (WAS),并且可以正常运行我的 Web 服务。
IIS(WAS)回收应用程序池后,我确定我的注册代码已被执行。 但现在 Web 服务抛出异常,比如
"Exception occurred while: while resolving."
然后我从 IIS 服务记录信息,说明我没有注册此类型。
最佳答案
我自己解决了这个问题。
当应用程序池回收并创建启动新的应用程序池时,所有DLL都会复制到新的Asp.Net模板文件夹中。
当我强制将所有“bin”DLL 加载到 AppDomain 时,我在 bin 的程序集中注册了一个类型。不在 Asp.net 临时文件夹程序集中。所以Unity认为这是差异类型。
现在我更改将程序集加载到当前域的方式
string binPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");
foreach (string dll in Directory.GetFiles(binPath, "*.dll", SearchOption.AllDirectories))
{
var assemblyFromCurrentDomain = Assembly.Load(Assembly.LoadFile(dll).FullName);
Debug.Print("Add Assembly : {0}, {1}", assemblyFromCurrentDomain.FullName, assemblyFromCurrentDomain.Location);
}
然后问题就解决了。
关于c# - WAS回收应用程序池后,使用Unity解析实例会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9390356/