// This method is used by the Cassini ASP.NET host application (and all of its // derivatives, e.g. CassiniDev, see http://cassinidev.codeplex.com) to register the // host assembly with System.Web's assembly resolver in order to enable loading // types from assemblies not installed in GAC. // protected void RegisterAssembly(string assemblyName, string assemblyLocation) { if (String.IsNullOrEmpty(assemblyName) || String.IsNullOrEmpty(assemblyLocation)) { return; } HttpRuntime.RegisteredAssemblies.InsertOrUpdate((uint)assemblyName.GetHashCode(), assemblyName, assemblyLocation, assemblyLocation); HttpRuntime.EnableAssemblyMapping(true); }
void BuildDefaultAssembly(List <string> files, CodeCompileUnit unit) { AssemblyBuilder abuilder = new AssemblyBuilder(Provider); if (unit != null) { abuilder.AddCodeCompileUnit(unit); } CompilerParameters cp = ci.CreateDefaultCompilerParameters(); cp.OutputAssembly = baseAssemblyPath; cp.GenerateExecutable = false; cp.TreatWarningsAsErrors = true; cp.IncludeDebugInformation = config.Debug; foreach (string f in files) { cp.EmbeddedResources.Add(f); } CompilerResults results = abuilder.BuildAssembly(cp); if (results == null) { return; } if (results.NativeCompilerReturnValue == 0) { mainAssembly = results.CompiledAssembly; BuildManager.TopLevelAssemblies.Add(mainAssembly); } else { if (HttpContext.Current.IsCustomErrorEnabled) { throw new ApplicationException("An error occurred while compiling global resources."); } throw new CompilationException(null, results.Errors, null); } HttpRuntime.WritePreservationFile(mainAssembly, canonicAssemblyName); HttpRuntime.EnableAssemblyMapping(true); }
public void Compile() { if (_alreadyCompiled) { return; } string appCode = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Code"); ProfileSection ps = WebConfigurationManager.GetWebApplicationSection("system.web/profile") as ProfileSection; bool haveAppCodeDir = Directory.Exists(appCode); bool haveCustomProfile = HaveCustomProfile(ps); if (!haveAppCodeDir && !haveCustomProfile) { return; } AppCodeAssembly defasm = new AppCodeAssembly("App_Code", appCode); assemblies.Add(defasm); bool haveCode = false; if (haveAppCodeDir) { haveCode = ProcessAppCodeDir(appCode, defasm); } if (haveCustomProfile) { if (ProcessCustomProfile(ps, defasm)) { haveCode = true; } } if (!haveCode) { return; } HttpRuntime.EnableAssemblyMapping(true); string[] binAssemblies = HttpApplication.BinDirectoryAssemblies; foreach (AppCodeAssembly aca in assemblies) { aca.Build(binAssemblies); } _alreadyCompiled = true; DefaultAppCodeAssemblyName = Path.GetFileNameWithoutExtension(defasm.OutputAssemblyName); RunAppInitialize(); if (haveCustomProfile && providerTypeName != null) { if (Type.GetType(providerTypeName, false) == null) { foreach (Assembly asm in BuildManager.TopLevelAssemblies) { if (asm == null) { continue; } if (asm.GetType(providerTypeName, false) != null) { return; } } } else { return; } Exception noTypeException = null; Type ptype = null; try { ptype = HttpApplication.LoadTypeFromBin(providerTypeName); } catch (Exception ex) { noTypeException = ex; } if (ptype == null) { throw new HttpException(String.Format("Profile provider type not found: {0}", providerTypeName), noTypeException); } } }