gpt4 book ai didi

c# - ApplicationHost.CreateApplicationHost : System. IO.FileNotFoundException

转载 作者:太空狗 更新时间:2023-10-30 01:26:26 24 4
gpt4 key购买 nike

我正在尝试使用 CreateApplicationHost 呈现 ASP 网页的内容。具体代码如下:

public class LocalPageContentAppropriator {
private RemoteDomain _host;
protected RemoteDomain Host {
get {
if (_host == null) {
_host = (RemoteDomain)ApplicationHost.CreateApplicationHost(typeof(RemoteDomain), "/", SettingsFactory.Instance.WebFileRoot + "\\");
}
return _host;
}
}

public string Resolve(string page, string query) {
return Host.ProcessRequest(page, query);
}
}

public class RemoteDomain : MarshalByRefObject {
public string ProcessRequest(string page, string query) {
using (StringWriter sw = new StringWriter()) {
SimpleWorkerRequest work = new SimpleWorkerRequest(page, query, sw);
HttpRuntime.ProcessRequest(work);
return sw.ToString();
}
}
}

SettingsFactory.Instance.WebFileRoot 返回的路径指向网站的物理目录。已尝试附加“\bin\”等,但无论我尝试什么,即使我故意输入不正确的路径,我仍然会收到相同的错误。

现在,有趣的地方来了。当程序集被正确加载(在正常使用下)时,Fusion Logging 通常会返回类似这样的内容:

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\windows\microsoft.net\framework\v4.0.30319\aspnet_wp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = WICKEDWE-FFB297\ASPNET
LOG: DisplayName = MyWebsite.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Projects/Clients/G/MyWebsite/Development/MasterSite/trunk/MyWebsite.Web.Site/
LOG: Initial PrivatePath = C:\Projects\Clients\G\Galderma\Emervel\Development\MasterSite\trunk\MyWebsite.Web.Site\bin
LOG: Dynamic Base = C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\3610448a\a3b3a5e7
LOG: Cache Base = NULL
LOG: AppName = Umbraco_Sandbox_98a12b84-6e7b-401f-a543-87e17c021ad5
Calling assembly : MyWebsite.Web.Site, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\Clients\G\Galderma\Emervel\Development\MasterSite\trunk\MyWebsite.Web.Site\web.config
LOG: Using host configuration file: c:\windows\microsoft.net\framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Binding succeeds. Returns assembly from C:\Projects\Clients\G\Galderma\Emervel\Development\MasterSite\trunk\MyWebsite.Web.Site\bin\MyWebsite.Web.dll.
LOG: Assembly is loaded in default load context.

但是,错误显示不同的(IMO 不正确)Appbase 路径:

2011-02-08 11:10:03,734 [T1] ERROR MyWebsite.Web.Site.Common.Controls.Forms.Register [L91] - Member registration.
System.IO.FileNotFoundException: Could not load file or assembly 'MyWebsite.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'MyWebsite.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.UnitySerializationHolder.GetRealObject(StreamingContext context)
at System.Web.Hosting.ApplicationManager.CreateInstanceInNewWorkerAppDomain(Type type, String appId, VirtualPath virtualPath, String physicalPath)
at System.Web.Hosting.ApplicationHost.CreateApplicationHost(Type hostType, String virtualDir, String physicalDir)
at MyWebsite.Web.LocalPageContentAppropriator.get_Host() in C:\Projects\Clients\G\MyWebsite\Development\MasterSite\trunk\MyWebsite.Web\LocalPageContentAppropriator.cs:line 17
at MyWebsite.Web.LocalPageContentAppropriator.Resolve(String page, String query) in C:\Projects\Clients\G\MyWebsite\Development\MasterSite\trunk\MyWebsite.Web\LocalPageContentAppropriator.cs:line 24
at MyWebsite.Model.ProfessionalMemberLogic.Create(IProfessionalMemberInput input, String completedPagePath, String activationEmailPath, String contextPath) in C:\Projects\Clients\G\MyWebsite\Development\MasterSite\trunk\MyWebsite\Model\ProfessionalMemberLogic.cs:line 66
at MyWebsite.Web.Site.Common.Controls.Forms.Register.btnRegister_Click(Object sender, EventArgs e) in C:\Projects\Clients\G\MyWebsite\Development\MasterSite\trunk\MyWebsite.Web.Site\Common\Controls\Forms\Register.ascx.cs:line 84

Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\windows\microsoft.net\framework\v4.0.30319\aspnet_wp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = WICKEDWE-FFB297\ASPNET
LOG: DisplayName = MyWebsite.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///c:/windows/microsoft.net/framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: c:\windows\microsoft.net\framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v4.0.30319/MyWebsite.Web.DLL.
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v4.0.30319/MyWebsite.Web/MyWebsite.Web.DLL.
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v4.0.30319/MyWebsite.Web.EXE.
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v4.0.30319/MyWebsite.Web/MyWebsite.Web.EXE.

有什么想法吗?

最佳答案

我现在不知道你是否得到了答案,但我正在尝试完全相同的事情并且遇到了完全相同的问题。

一个也是最简单的方法是将程序集放入 GAC 中。

第二,有点棘手的是,将您的程序集复制到“physicalDir”目录中的“bin”目录,用作 ApplicationHost.CreateApplicationHost 方法的参数。

这里有很好的解释:http://www.west-wind.com/Weblog/posts/2613.aspx

关于c# - ApplicationHost.CreateApplicationHost : System. IO.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4932489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com