I'm trying to use CreateApplicationHost to render the content of an ASP webpage. The exact code is as follows:
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();
}
}
}
The path returned for SettingsFactory.Instance.WebFileRoot points to the website's physical directory. Have tried putting appending "\bin\", etc but regardless of what I try I still receive the same error, even if I intentionally enter an incorrect path.
Now, here's where it gets interesting. Fusion Logging usually returns something like this when the assembly is loaded correctly (under normal use):
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.
However, the error shows a different (IMO incorrect) Appbase path:
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.
Any ideas guys?
I don't now if you get your answer or not, but I'm trying exactly the same thing and had exactly the same problems.
One, and most simple, is to put your assembly inside GAC.
Two, and a little bit tricky, is to copy your assembly to the 'bin' directory inside the directory 'physicalDir' used as parameter to ApplicationHost.CreateApplicationHost method.
It is well explained here: http://www.west-wind.com/Weblog/posts/2613.aspx
The implementation of ApplicationHost.CreateApplicationHost expects to find the assembly of the specified type in one of two places: either in the Global Assembly Cache (GAC) or within the bin directory under the specified physical directory. There is no documented way to change this behavior short of reimplementing CreateApplicationHost. So depending on your project configuration and deployment scenario, you may need to install the assembly into one of these locations.
Please take a look here for more details.
Idealty, your host will be in different assembly (that you deploy under "bin" of your physical server dir).
Related
I add the file to the directory but it is still telling me that it cannot find the file. What am I suppose to do now to fix this error?
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'CrystalDecisions.Web, Version=13.0.32.4286, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 18:
Line 19:
Line 20:
Line 21:
Line 22:
Source File: C:\inetpub\wwwroot\POS\web.config Line: 20
Assembly Load Trace: The following information can be helpful to determine why the assembly 'CrystalDecisions.Web, Version=13.0.32.4286, Culture=neutral, PublicKeyToken=692fbea5521e1304' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = CrystalDecisions.Web, Version=13.0.32.4286, Culture=neutral, PublicKeyToken=692fbea5521e1304
(Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/POS/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\POS\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\POS\web.config
LOG: Using host configuration file: C:\Users\okdok\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: CrystalDecisions.Web, Version=13.0.32.4286, Culture=neutral, PublicKeyToken=692fbea5521e1304
LOG: Attempting download of new URL file:///C:/Users/okdok/AppData/Local/Temp/Temporary ASP.NET Files/vs/28ae311b/78674aee/CrystalDecisions.Web.DLL.
LOG: Attempting download of new URL file:///C:/Users/okdok/AppData/Local/Temp/Temporary ASP.NET Files/vs/28ae311b/78674aee/CrystalDecisions.Web/CrystalDecisions.Web.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/POS/bin/CrystalDecisions.Web.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
<assemblies>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
Also do you know what I should do about this error:
Could not load file or assembly 'Microsoft.ReportingServices.Interfaces' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Microsoft.ReportingServices.Interfaces' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportingServices.Interfaces' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Microsoft.ReportingServices.Interfaces
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.ReportingServices.Interfaces | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/inetpub/wwwroot/POS/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\POS\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\POS\web.config
LOG: Using host configuration file: C:\Users\okdok\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\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:/Users/okdok/AppData/Local/Temp/Temporary ASP.NET Files/vs/28ae311b/78674aee/Microsoft.ReportingServices.Interfaces.DLL.
LOG: Attempting download of new URL file:///C:/Users/okdok/AppData/Local/Temp/Temporary ASP.NET Files/vs/28ae311b/78674aee/Microsoft.ReportingServices.Interfaces/Microsoft.ReportingServices.Interfaces.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/POS/bin/Microsoft.ReportingServices.Interfaces.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Microsoft.ReportingServices.Interfaces' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +113
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +23
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.ReportingServices.Interfaces' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +762
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +167
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +238
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +78
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +334
System.Web.Compilation.BuildManager.ExecutePreAppStart() +178
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +746
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.ReportingServices.Interfaces' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737
I have read the following article http://msdn.microsoft.com/en-us/library/ff650307.aspx, about how i can authenticate asp.net mvc users from multiple domains, so inside my asp.net mvc i did the following :-
I added the following to my web.config:-
<system.web>
<membership>
<providers>
<add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain1ConnectionString" connectionUsername="ad-domainA.intra\it360ad.user" connectionPassword="$$$$$" />
</providers>
</membership>
&
<connectionStrings>
<add name="TestDomain1ConnectionString" connectionString="LDAP://ad-domainA.intra/CN=Users,DC=ad-domainA,DC=intra" />
and i added the following Account.controller:-
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
MembershipProvider domainProvider;
domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];
// Validate the user with the membership system.
if (domainProvider.ValidateUser(model.UserName, model.Password))
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(
model.UserName, false);
}
else
{
// If there is no RequestUrl query string attribute, just set
// the authentication cookie. Provide navigation on the login page
// to pages that require authentication, or user can use browser
// to navigate to protected pages.
// Set second parameter to false so cookie is not persistent
// across sessions.
FormsAuthentication.SetAuthCookie(model.UserName, false);
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
return RedirectToLocal(returnUrl);
}
but when i type my user name and password inside the login screen and click on enter , i got the following error:-
System.Configuration.ConfigurationErrorsException was unhandled by
user code HResult=-2146232062 Message=Could not load file or
assembly 'System.Web, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
(C:\Users\john.john\Desktop\test login\TMS\TMS\web.config line 39)
Source=System.Web BareMessage=Could not load file or assembly
'System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.
Filename=C:\Users\john.john\Desktop\test login\TMS\TMS\web.config
Line=39 StackTrace:
at System.Web.Security.Membership.Initialize()
at System.Web.Security.Membership.get_Providers() InnerException: System.IO.FileNotFoundException
HResult=-2147024894
Message=Could not load file or assembly 'System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
Source=mscorlib
FileName=System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
FusionLog==== Pre-bind state information === LOG: User = AD-ITSERVICES\john.john LOG: DisplayName = System.Web,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Partial) WRN:
Partial binding information was supplied for an assembly: WRN:
Assembly Name: System.Web, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a | Domain ID: 4 WRN: A partial bind
occurs when only part of the assembly display name is provided. WRN:
This might result in the binder loading an incorrect assembly. WRN: It
is recommended to provide a fully specified textual identity for the
assembly, WRN: that consists of the simple name, version, culture, and
public key token. WRN: See whitepaper
http://go.microsoft.com/fwlink/?LinkId=109270 for more information and
common solutions to this issue. LOG: Appbase =
file:///C:/Users/john.john/Desktop/test login/TMS/TMS/ LOG: Initial
PrivatePath = C:\Users\john.john\Desktop\test login\TMS\TMS\bin
Calling assembly : (Unknown).
=== LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\john.john\Desktop\test
login\TMS\TMS\web.config LOG: Using host configuration file:
C:\Users\john.john\Documents\IISExpress\config\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:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET
Files/root/2fc69b03/2c0137b8/System.Web.DLL. LOG: Attempting download
of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary
ASP.NET Files/root/2fc69b03/2c0137b8/System.Web/System.Web.DLL. LOG:
Attempting download of new URL file:///C:/Users/john.john/Desktop/test
login/TMS/TMS/bin/System.Web.DLL. LOG: Attempting download of new URL
file:///C:/Users/john.john/Desktop/test
login/TMS/TMS/bin/System.Web/System.Web.DLL. LOG: Attempting download
of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary
ASP.NET Files/root/2fc69b03/2c0137b8/System.Web.EXE. LOG: Attempting
download of new URL
file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET
Files/root/2fc69b03/2c0137b8/System.Web/System.Web.EXE. LOG:
Attempting download of new URL file:///C:/Users/john.john/Desktop/test
login/TMS/TMS/bin/System.Web.EXE. LOG: Attempting download of new URL
file:///C:/Users/john.john/Desktop/test
login/TMS/TMS/bin/System.Web/System.Web.EXE.
StackTrace:
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean
loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement,
XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase)
InnerException:
on the following line of code inside the Account controller:-
public ActionResult Login(LoginModel model, string returnUrl)
{MembershipProvider domainProvider;
domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];
so what is causing this error?
For this declaration of System.Web
System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
The version is also needed (4.0 right?)
Version=4.0.0.0
I want to instantiate a class at runtime using
_syncHelper = (ISyncHelper) Activator.CreateInstance("SBD.Syrius.Synchronisation", "SyncHelper");
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
System.IO.FileNotFoundException: Could not load file or assembly
'SBD.Syrius.Synchronisation' or one of its dependencies. The system cannot find the file specified.
File name: 'SBD.Syrius.Synchronisation'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51
=== Pre-bind state information ===
LOG: User = saturn\kirsten
LOG: DisplayName = SBD.Syrius.Synchronisation
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SBD.Syrius.Synchronisation | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information
and common solutions to this issue.
LOG: Appbase = file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : SBD.Syrius.DataLayer, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\bin\Debug\SBD.Syrius.UI.vshost.exe.Config
LOG: Using host configuration file:
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:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.EXE.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/ SBD.Syrius.Synchronisation.EXE.
The error I receive contains a link to MSDN here, but I cannot find an example of how to specify textual identity for the assembly.
I note that the full error indicates that it is looking int the wrong folder and also for a file with an uppercase .DLL . My file is creating with a lowercase .dll
Is there an example of how to provide a fully specified textual identity for an assembly?
Should I be trying to change the case of the .dll extension?
If I actually copy the .dll to the UI\bin\debug folder then I get a different error
A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll
System.TypeLoadException: Could not load type 'SyncHelper'
from assembly
'SBD.Syrius.Synchronisation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name,
Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51
Spot three errors:
Activator.CreateInstance needs the complete name of type to load it
it means that you must add namespace to the type name.
Chances are you have more than one class with that name in different namespaces then how it could figure out which one be loaded.
You want to create an instance of an Interface which is impossible.
ISyncHelper is an interface and you can not say:
var variable = new ISynchHelper()
It will cause compilation error, cause interfaces are just empty bodies and does not contain single line of implementation.
So evertime that you use reflection to do smething, be careful, cause the compiler can not help you and if something is supposed to go wrong, you'll face it in runtime, not in compile time.
Last error is due to that there is no reference to Synchronization project in UI which means that it will not copied to Bin folder of UI project.
You can do that by adding the Synchronization project to UI or just add a copy command to Synchronization project to be copied after build.
Good Luck :-)
I have a very simple class CompiledFunction (MarshalByRefObject) - I try to create an instance of this in a new domain like so
var appDomainSetup = new AppDomainSetup();
appDomainSetup.ApplicationBase = Path.GetDirectoryName(typeof(CompilerService).Assembly.CodeBase);
var evidence = AppDomain.CurrentDomain.Evidence;
SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);
CompiledFunction<T> result = (CompiledFunction<T>)SandboxDomain.CreateInstanceAndUnwrap(
assemblyName: typeof(CompiledFunction<T>).Assembly.GetName().Name,
typeName: typeof(CompiledFunction<T>).FullName);
This works fine in a Console application, but in an ASP .NET MVC application I get the following exception - can anyone offer any suggestion as to why this is not working in a web app? The T parameter I am passing is System.Decimal
System.IO.FileLoadException was caught
Message=The given assembly name or codebase, 'Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', was invalid.
Source=mscorlib
FileName=Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
FusionLog==== Pre-bind state information ===
LOG: User = EMSLaptop\PeterMorris
LOG: DisplayName = Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Found application configuration file (C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe.Config).
LOG: Using application configuration file: C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe.Config
LOG: Using host configuration file:
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 /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin/Ems.Scripting.DLL.
StackTrace:
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.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at Ems.Scripting.CompilerService.Compile[T](String[] scripts, Dictionary`2 variableDefinitions, IEnumerable`1 referencedAssemblies, ICompiledFunction`1& function, IEnumerable`1& compilerErrors) in C:\Data\EMS\Lib\Ems.Scripting\CompilerService.cs:line 43
InnerException:
The problem was that the Assembly.Code base started with file:///{rest of path here} - when using Path.GetDirectoryName on such a path it replaces file:/// with a single forward slash; so you end up with "/c:\myfolder\myfile.dll"
Getting Uri to tell me the local path was the solution
if (SandboxDomain == null)
{
var appDomainSetup = new AppDomainSetup();
string appBase = typeof(CompilerService).Assembly.CodeBase;
//Added the following line
appBase = new Uri(appBase).LocalPath;
appDomainSetup.ApplicationBase = Path.GetDirectoryName(appBase);
var evidence = AppDomain.CurrentDomain.Evidence;
SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);
}
Looks like you did not properly copy Ems.Scripting assembly for web project or set wrong ApplicationBase for your new domain (more likely).
Path.GetDirectoryName call is suspicious in computing ApplicationBase property.
We have a simple task that, before compiling, makes all of our AssemblyInfo.cs files editable, then updates
[assembly: AssemblyVersion("1.0.0.0")]
to
[assembly: AssemblyVersion("1.0.0.<SourceGetVersion>")]
All of our assemblies are signed using the same key.
This kind of thing is probably fairly standard, and it works just fine, except that it causes test failures.
The failures look like this:
Test method
Namespace.Tests.MessageTest.TestMethod
threw exception:
System.IO.FileLoadException: Could not
load file or assembly
'Namespace.BusinessLayer.BusinessComponent.Documents,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
So, I turned on the logging that was suggested, and get this:
W, 3964, 90, 2010/12/07, 09:57:43.059,
TFSBUILD\QTAgent32.exe, Getting
custom attributes for type
System.Reflection.RuntimeMethodInfo
threw exception (will ignore and use
the reflection way):
System.IO.FileLoadException: Could not
load file or assembly
'Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
File name:
'Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' at
System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule
pModule, IRuntimeMethodInfo pCtor,
Byte** ppBlob, Byte* pEndBlob, Int32*
pcNamedArgs) at
System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule
module, IRuntimeMethodInfo ctor,
IntPtr& blob, IntPtr blobEnd, Int32&
namedArgs) at
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32
decoratedMetadataToken, Int32
pcaCount, RuntimeType
attributeFilterType, Boolean
mustBeInheritable, IList
derivedAttributes, Boolean
isDecoratedTargetSecurityTransparent)
at
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo
method, RuntimeType caType, Boolean
inherit) at
System.Reflection.RuntimeMethodInfo.GetCustomAttributes(Boolean
inherit) at
Microsoft.VisualStudio.TestTools.Common.ReflectHelper.GetAttributes(MemberInfo
info, Boolean bInherit)
=== Pre-bind state information === LOG: User = domain\tfsbuildAccount
LOG: DisplayName =
Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx
(Fully-specified) LOG: Appbase =
file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD
2010-12-07 09_56_54_x86_Debug/Out LOG:
Initial PrivatePath = NULL Calling
assembly :
Namespace.BusinessLayer.BusinessComponent.Edi.Tests,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx.
=== LOG: This bind starts in default load context. LOG: Using application
configuration file:
D:\Builds\4\10\TestResults\tfsbuildAccount-TFSBUILD
2010-12-07
09_56_54_x86_Debug\Out\Namespace.BusinessLayer.BusinessComponent.Edi.Tests.DLL.config
LOG: Using host configuration file:
LOG: Using machine configuration file
from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference:
Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx LOG:
Attempting download of new URL
file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD
2010-12-07
09_56_54_x86_Debug/Out/Namespace.BusinessLayer.BusinessEntity.DLL.
WRN: Comparing the assembly name
resulted in the mismatch: Revision
Number ERR: Failed to complete setup
of assembly (hr = 0x80131040). Probing
terminated.
Now, I may have mixed up the assemblies posting this, but it's the same pattern for all the tests. Mind you, the public keys are all the same, and I can see that all of the revision numbers are the same.
What are we doing wrong?
Try changing the reference assebly to be not version specific. "Secific Version = False" in the properties tab for the assembly.