public void IsCompatibilitySwitchSet() { Assert.Throws <ArgumentNullException> (delegate { AppDomain.CurrentDomain.IsCompatibilitySwitchSet(null); }, "null"); Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet(String.Empty), "Empty"); // defined in SL4 (final) documentation bool v3 = (Deployment.Current.RuntimeVersion [0] == '3'); Assert.AreEqual(v3, (bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("APP_EARLIER_THAN_SL4.0"), "APP_EARLIER_THAN_SL4.0"); // defined in FX4 (final) documentation Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("NetFx40_LegacySecurityPolicy"), "NetFx40_LegacySecurityPolicy"); Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("NetFx40_Legacy20SortingBehavior"), "NetFx40_Legacy20SortingBehavior"); Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("NetFx40_TimeSpanLegacyFormatMode"), "NetFx40_TimeSpanLegacyFormatMode"); // undefined Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("MONO"), "undefined"); // we can set compatibility switches on an AppDomainSetup but we // can't associate it with the current domain so they get ignored AppDomainSetup ads = new AppDomainSetup(); try { ads.SetCompatibilitySwitches(new[] { "MONO" }); Assert.IsFalse((bool)AppDomain.CurrentDomain.IsCompatibilitySwitchSet("MONO"), "undefined"); } finally { ads.SetCompatibilitySwitches(null); } }
public static byte[] RenderReport(string reportPath, string rdlcDSName, DataTable rdlcDt, ReportParameter[] rptParams, string downloadFormat, out string mimeType, out string filenameExtension) { var assemblyDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); AppDomainSetup setup = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, LoaderOptimization = LoaderOptimization.MultiDomainHost, PrivateBinPath = assemblyDir }; setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); AppDomain _casPolicyEnabledDomain = AppDomain.CreateDomain("Full Trust", null, setup); try { FullTrustReportviewer rpt = (FullTrustReportviewer)_casPolicyEnabledDomain.CreateInstanceFromAndUnwrap(typeof(FullTrustReportviewer).Assembly.CodeBase, typeof(FullTrustReportviewer).FullName); rpt.Initialize(reportPath, rptParams); var bytes = rpt.Render(rdlcDSName, rdlcDt, downloadFormat, out mimeType, out filenameExtension); return(bytes); } finally { AppDomain.Unload(_casPolicyEnabledDomain); } }
public static ReportViewerReturn Render(DataTable table, List <string> allFields, List <KeyValuePair <string, bool> > selectedFields, List <KeyValuePair <string, bool> > headers, tpeExport exportFormat) { AppDomainSetup setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory, LoaderOptimization = LoaderOptimization.MultiDomainHost }; setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); AppDomain _casPolicyEnabledDomain = AppDomain.CreateDomain("Full Trust", null, setup); try { FullTrustReportViewer rvNextgenReport2 = (FullTrustReportViewer)_casPolicyEnabledDomain.CreateInstanceFromAndUnwrap(typeof(FullTrustReportViewer).Assembly.CodeBase, typeof(FullTrustReportViewer).FullName); // rvNextgenReport2.LoadReportDefinition(allFields, selectedFields, headers); rvNextgenReport2.AddDataSources(table); // var exportName = string.Empty; switch (exportFormat) { case tpeExport.Excel2003: exportName = "Excel"; break; case tpeExport.Excel: exportName = "EXCELOPENXML"; break; case tpeExport.Word2003: exportName = "Word"; break; case tpeExport.Word: exportName = "WORDOPENXML"; break; case tpeExport.PDF: exportName = "PDF"; break; case tpeExport.Image: exportName = "IMAGE"; break; } // string mimeType; string fileNameExtension; // byte[] array = rvNextgenReport2.Render(exportName, out mimeType, out fileNameExtension); return(new ReportViewerReturn() { array = array, fileNameExtension = fileNameExtension, mimeType = mimeType }); } finally { AppDomain.Unload(_casPolicyEnabledDomain); } }
public static void Main() { AppDomainSetup appSetup = new AppDomainSetup(); appSetup.SetCompatibilitySwitches(new string[] { "NetFx40_TimeSpanLegacyFormatMode" }); AppDomain legacyDomain = AppDomain.CreateDomain("legacyDomain", null, appSetup); legacyDomain.ExecuteAssembly("ShowTimeSpan.exe"); }
private AppDomainSetup GetAppDomainSetup(bool legacyCasEnabled) { var setup = new AppDomainSetup(); if (legacyCasEnabled) { setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); } return(setup); }
private AppDomainSetup GetAppDomainSetup(bool legacyCasEnabled) { var setup = new AppDomainSetup(); if (legacyCasEnabled) { setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); } return setup; }