[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

ApplicationHost.CreateApplicationHost failing with File not found?

Rick Strahl

12/14/2002 8:49:00 PM


I have the following code:

RuntimeHost host =
(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RuntimeHost), "/",
Directory.GetCurrentDirectory());

which results in:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in
mscorlib.dll
Additional information: File or assembly name RichUserInterface, or one of
its dependencies, was not found.

The class is however defined in the same module and should be accessible.

I've been playing with code that originally came from VS Magazine, but that
sample fails with the same error as do any other samples I've looked at on
the Web. They all fail on the CreateApplicationHost().

Can anybody point me in the right direction of what's not being found?

I posted the abridged code below.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro



using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Runtime.Remoting;
using System.Xml;

namespace RichUserInterface {

public class RuntimeHost : MarshalByRefObject
{

public static string cHostPath = "d:\\projects\\...";
public static string cVirtualPath = "/WebDir";
public static string cScriptPage = "test.aspx";
public static string cOutputHTML = "d:\\temp\\__preview.htm";

public void ProcessRequest(String page)
{

TextWriter twHTML;
twHTML = File.CreateText(cOutputHTML);
HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null, twHTML));
twHTML.Close();

}

}

public class RuntimeHostApplication
{
public static void Main()
{

RuntimeHost host =
(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RichUserInterface.
RuntimeHost),
"/", Directory.GetCurrentDirectory());

host.ProcessRequest(RuntimeHost.cScriptPage);

}

}
}



--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro


2 Answers

(Felix Wu [MS])

12/16/2002 2:18:00 PM

0

Hi Rick,

Check the following link to see if it helps:

http://www.csharphelp.com/archives/archi...

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Rick Strahl [MVP]" <RickStrahl@hotmail.com>
>Subject: ApplicationHost.CreateApplicationHost failing with File not found?
>Date: Sat, 14 Dec 2002 09:49:22 -1000
>Lines: 96
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.3604.0
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3604.0
>Message-ID: <eMpKpn6oCHA.2084@TK2MSFTNGP12>
>Newsgroups: microsoft.public.dotnet.framework.sdk
>NNTP-Posting-Host: a66b91n6client145.hawaii.rr.com 66.91.6.145
>Path: cpmsftngxa06!tkmsftngp01!TK2MSFTNGP08!TK2MSFTNGP12
>Xref: cpmsftngxa06 microsoft.public.dotnet.framework.sdk:5399
>X-Tomcat-NG: microsoft.public.dotnet.framework.sdk
>
>
>I have the following code:
>
>RuntimeHost host =
>(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RuntimeHost),
"/",
>Directory.GetCurrentDirectory());
>
>which results in:
>An unhandled exception of type 'System.IO.FileNotFoundException' occurred
in
>mscorlib.dll
>Additional information: File or assembly name RichUserInterface, or one of
>its dependencies, was not found.
>
>The class is however defined in the same module and should be accessible.
>
>I've been playing with code that originally came from VS Magazine, but that
>sample fails with the same error as do any other samples I've looked at on
>the Web. They all fail on the CreateApplicationHost().
>
>Can anybody point me in the right direction of what's not being found?
>
>I posted the abridged code below.
>
>+++ Rick ---
>
>--
>
>Rick Strahl
>West Wind Technologies
>http://www.west...
>http://www.west...wwthreads/
>-----------------------------------
>Making waves on the Web with Visual FoxPro
>
>
>
>using System;
>using System.Diagnostics;
>using System.IO;
>using System.Text;
>using System.Web;
>using System.Web.Hosting;
>using System.Runtime.Remoting;
>using System.Xml;
>
>namespace RichUserInterface {
>
>public class RuntimeHost : MarshalByRefObject
>{
>
> public static string cHostPath = "d:\\projects\\...";
> public static string cVirtualPath = "/WebDir";
> public static string cScriptPage = "test.aspx";
> public static string cOutputHTML = "d:\\temp\\__preview.htm";
>
> public void ProcessRequest(String page)
> {
>
> TextWriter twHTML;
> twHTML = File.CreateText(cOutputHTML);
> HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null, twHTML));
> twHTML.Close();
>
> }
>
>}
>
>public class RuntimeHostApplication
>{
> public static void Main()
> {
>
> RuntimeHost host =
>(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RichUserInterface

Rick Strahl

12/16/2002 8:08:00 PM

0

Thanks,

Yes, it answers that question <g>, and I don't like it.

The solution is to manually create our own AppDomain in the current app
directory and point the physicalpath and vdirectory at the appropriate
directories. This makes the app find all files in the current appbase path
which means nothing needs to be duplicated.

I found this article on third party site, but it would be nice to find some
official documentation on exactly what settings on the AppDomain are
availalbe to be used by the Asp.Net Runtime host.

Here's the code:

{
if (!(physicalDir.EndsWith("\\")))
physicalDir = physicalDir + "\\";

string aspDir = HttpRuntime.AspInstallDirectory;
string domainId = "ASPHOST_" +
DateTime.Now.ToString().GetHashCode().ToString("x");
string appName = (virtualDir + physicalDir).GetHashCode().ToString("x");
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;

setup.ConfigurationFile = "web.config"; // not necessary execept for
debugging

AppDomain loDomain = AppDomain.CreateDomain(domainId, null, setup);
loDomain.SetData(".appDomain", "*");
loDomain.SetData(".appPath", physicalDir);
loDomain.SetData(".appVPath", virtualDir);
loDomain.SetData(".domainId", domainId);
loDomain.SetData(".hostingVirtualPath", virtualDir);
loDomain.SetData(".hostingInstallDir", aspDir);

ObjectHandle oh =
loDomain.CreateInstance(hostType.Module.Assembly.FullName,
hostType.FullName);

// *** Save the AppDomain Reference
AspRuntimeHost loHost = (AspRuntimeHost) oh.Unwrap();
loHost.oAppDomain = loDomain;

return loHost;
}

This method can be used instead of ApplicationHost.CreateApplicationHost to
provide the Application domain ( you need to cast to (object) instead of
(AspRuntimeHost) which is my Runtime subclass to keep things more generic).

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro
"Felix Wu(MS)" <felixwu@online.microsoft.com> wrote in message
news:jQGvuWQpCHA.2304@cpmsftngxa06...
> Hi Rick,
>
> Check the following link to see if it helps:
>
> http://www.csharphelp.com/archives/archi...
>
> Regards,
>
> Felix Wu
> =============
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
> --------------------
> >From: "Rick Strahl [MVP]" <RickStrahl@hotmail.com>
> >Subject: ApplicationHost.CreateApplicationHost failing with File not
found?
> >Date: Sat, 14 Dec 2002 09:49:22 -1000
> >Lines: 96
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.3604.0
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3604.0
> >Message-ID: <eMpKpn6oCHA.2084@TK2MSFTNGP12>
> >Newsgroups: microsoft.public.dotnet.framework.sdk
> >NNTP-Posting-Host: a66b91n6client145.hawaii.rr.com 66.91.6.145
> >Path: cpmsftngxa06!tkmsftngp01!TK2MSFTNGP08!TK2MSFTNGP12
> >Xref: cpmsftngxa06 microsoft.public.dotnet.framework.sdk:5399
> >X-Tomcat-NG: microsoft.public.dotnet.framework.sdk
> >
> >
> >I have the following code:
> >
> >RuntimeHost host =
> >(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RuntimeHost),
> "/",
> >Directory.GetCurrentDirectory());
> >
> >which results in:
> >An unhandled exception of type 'System.IO.FileNotFoundException' occurred
> in
> >mscorlib.dll
> >Additional information: File or assembly name RichUserInterface, or one
of
> >its dependencies, was not found.
> >
> >The class is however defined in the same module and should be accessible.
> >
> >I've been playing with code that originally came from VS Magazine, but
that
> >sample fails with the same error as do any other samples I've looked at
on
> >the Web. They all fail on the CreateApplicationHost().
> >
> >Can anybody point me in the right direction of what's not being found?
> >
> >I posted the abridged code below.
> >
> >+++ Rick ---
> >
> >--
> >
> >Rick Strahl
> >West Wind Technologies
> >http://www.west...
> >http://www.west...wwthreads/
> >-----------------------------------
> >Making waves on the Web with Visual FoxPro
> >
> >
> >
> >using System;
> >using System.Diagnostics;
> >using System.IO;
> >using System.Text;
> >using System.Web;
> >using System.Web.Hosting;
> >using System.Runtime.Remoting;
> >using System.Xml;
> >
> >namespace RichUserInterface {
> >
> >public class RuntimeHost : MarshalByRefObject
> >{
> >
> > public static string cHostPath = "d:\\projects\\...";
> > public static string cVirtualPath = "/WebDir";
> > public static string cScriptPage = "test.aspx";
> > public static string cOutputHTML = "d:\\temp\\__preview.htm";
> >
> > public void ProcessRequest(String page)
> > {
> >
> > TextWriter twHTML;
> > twHTML = File.CreateText(cOutputHTML);
> > HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null,
twHTML));
> > twHTML.Close();
> >
> > }
> >
> >}
> >
> >public class RuntimeHostApplication
> >{
> > public static void Main()
> > {
> >
> > RuntimeHost host =
>
>(RuntimeHost)ApplicationHost.CreateApplicationHost(typeof(RichUserInterface