Shared domain for app domain while trying to run microsoft reportviwer in legacy mode

0

I am aiming to have Microsoft report viewer on .net 4.x with .net 3.5 with NetFx40_LegacySecurityPolicy as noted here

With full trust I got

Loading this assembly would produce a different grant set from other instances.

When try with relevant permissions by signing assemblies:

PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
permissions.AddPermission(new FileIOPermission(PermissionState.None) { AllFiles = FileIOPermissionAccess.Read });

it says Local mode requires full trust.

Here Shared domain is mentioned:

The problem is that some assemblies (most notably, interop assemblies) are not domain-specific. They use a shared domain, and thus they can only be loaded once in a process. You need to make sure that all the domains use the exact same assembly when that's the case. Or use full trust, but that comes with its own can of worms, of course :)

For shared domain, Here there is a listing like this:

…where each of the subwebs HrWeb, EmployeeServices etc. are set up as an application in the internet service manager, you will have the following application domains (appdomains) in your asp.net process

System Domain
Shared Domain
Default Domain
Root
HrWeb
EmployeeServices
FinanceWeb
SalesWeb

and here said:

Any assembly can be loaded by the CLR either into the shared domain or the domain that triggered the assembly load depending on the configuration of the CLR instance that is loading the assembly.

My first question, what is "Shared domain", is it related to shared hosting?

This link explains about "shared domain" by depicting with illustration with arguement:

When you load an assembly into your (default) AppDomain you will load it only for your current AppDomain. The types defined there are not shared anywhere. There is one exception though: The types defined in mscorlib are always shared between all AppDomains. The mscorlib assembly is loaded into a so called Shared Domain. This is not a real AppDomain but simply a placeholder domain where all assemblies are loaded which can be shared between AppDomains. An assembly loaded into the Shared Domain is loaded therefore AppDomain neutral. Assemblies loaded AppDomain neutral have one special behavior:

enter image description here

So my understanding, Shared domain is on top of appdomain. But how is s it related to shared hosting? Is it w3wp.exe process has appdomains and shared domain?

On the other hand, if I play with set the AppDomainSetup.LoaderOptimization property, I am stuck as well because:

Here, it is said LoaderOptimization attribute can not be changed for iis.

However to verify I both tried with

        AppDomainSetup setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory, LoaderOptimization = LoaderOptimization.SingleDomain };

and

        AppDomainSetup setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory, LoaderOptimization = LoaderOptimization.MultiDomain };

but always result with:

Exception has been thrown by the target of an invocation.|[!] Exception has been thrown by the target of an invocation.
The type initializer for 'Microsoft.Reporting.WebForms.ReportViewer' threw an exception.
Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401) 

Second question is: I can produce report in dev machine however in test machine it fails with error message above with full trust issues. How can I reproduce the same error on my dev machine?

So finally How can I produce properly my report on test machine? Is it cause to use multiple application on the same domain? Do I need dedicated iis domain for this?

c#
reportviewer
appdomain
asked on Stack Overflow Jul 18, 2019 by asdf_enel_hak • edited Jul 18, 2019 by asdf_enel_hak

1 Answer

0

I hope I well documented my question for further readers.

I found answer here:

AppDomain cad = AppDomain.CurrentDomain;
AppDomainSetup cads = cad.SetupInformation;
var setup = new AppDomainSetup
{
    ApplicationName = cads.ApplicationName,
    ApplicationBase = cads.ApplicationBase,
    DynamicBase = cads.DynamicBase,
    CachePath = cads.CachePath,
    PrivateBinPath = cads.PrivateBinPath,
    ShadowCopyDirectories = cads.ShadowCopyDirectories,
    ShadowCopyFiles = cads.ShadowCopyFiles,
    ApplicationTrust = cads.ApplicationTrust,
    LoaderOptimization = LoaderOptimization.SingleDomain
};
setup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" });
AppDomain _casPolicyEnabledDomain = AppDomain.CreateDomain("Dummy", cad.Evidence,setup
);

Until that answer what I was missing which would inherit all setup properties from the current one but LoaderOptimization. That means I was only doing:

AppDomainSetup setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory, LoaderOptimization = LoaderOptimization.SingleDomain }; 
AppDomain _casPolicyEnabledDomain = AppDomain.CreateDomain("Full Trust", null, setup);
answered on Stack Overflow Jul 18, 2019 by asdf_enel_hak

User contributions licensed under CC BY-SA 3.0