ApplicationHost.CreateApplicationHost: System.IO.FileNotFoundException - PullRequest
4 голосов
/ 08 февраля 2011

Я пытаюсь использовать 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) путь к базе данных:

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.

Есть идеи, ребята?

Ответы [ 2 ]

4 голосов
/ 14 марта 2011

Не знаю, получил ли вы свой ответ или нет, но я пытаюсь точно так же, и у меня были точно такие же проблемы.

Один и самый простой способ - поместить вашу сборку в GAC.

Два, и немного хитроумно, - скопировать вашу сборку в каталог 'bin' внутри каталога 'physicalDir', используемого в качестве параметра метода ApplicationHost.CreateApplicationHost.

Это хорошо объяснено здесь: http://www.west -wind.com / Weblog / posts / 2613.aspx

0 голосов
/ 29 июля 2013

Реализация ApplicationHost.CreateApplicationHost предполагает поиск сборки указанного типа в одном из двух мест: либо в глобальном кэше сборок (GAC), либо в каталоге bin в указанном физическом каталоге. Не существует документированного способа изменить это поведение, кроме как реализовать CreateApplicationHost. Поэтому, в зависимости от конфигурации вашего проекта и сценария развертывания, вам может потребоваться установить сборку в одно из этих мест.

Пожалуйста, посмотрите здесь для более подробной информации.

В идеале, ваш хост будет находиться в другой сборке (которую вы развернете в «bin» директории вашего физического сервера).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...