RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

'AppDomainSetup' does not contain a constructor that takes 0 arguments

Open sybaris opened this issue 2 years ago • 6 comments

Hi,

I am using .NET 6.0 and RazorEngine.NetCore.

From documentation, I copy/paste the following snippet of code :

            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                Console.WriteLine("Switching to secound AppDomain, for RazorEngine...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                var exitCode = domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location);
                // RazorEngine will cleanup. 
                AppDomain.Unload(domain);
                return exitCode;
            }

And I have a build error : 'AppDomainSetup' does not contain a constructor that takes 0 arguments. What is the solution ? Is it possible to fix also the documentation please ?

Regards Sybaris

sybaris avatar Jun 03 '23 06:06 sybaris

This codebase hasn't been updated in a while and feels pretty abandoned. I'm using this in .Net Framework 4.6 and I'm starting to migrate a lot of stuff to Net 6. This is one of the lingering things I have to replace as we use this for a lot of email generation. If you find a working solution to getting this fully operation in Net 6, please let us know.

GaryWayneSmith avatar Aug 31 '23 21:08 GaryWayneSmith

Thanks for answering me. For information, I abandoned this project, and instead I use RazorLight which is more responsive in terms of answering questions, and the code seems more stable...

sybaris avatar Sep 01 '23 11:09 sybaris

Is someone finally going to answer this question? Why is there one thing in the documentation, but another in reality? Have Microsoft developers forgotten a whole stack of technologies?

mshakurov avatar Jan 16 '24 18:01 mshakurov

Is someone finally going to answer this question? Why is there one thing in the documentation, but another in reality? Have Microsoft developers forgotten a whole stack of technologies?

This is pretty much a dead project. I have been searching for viable alternatives for some time as I transition over to a new code base.

GaryWayneSmith avatar Jan 16 '24 18:01 GaryWayneSmith

Is someone finally going to answer this question? Why is there one thing in the documentation, but another in reality? Have Microsoft developers forgotten a whole stack of technologies?

This is pretty much a dead project. I have been searching for viable alternatives for some time as I transition over to a new code base.

I mean.. Is there a way to load an assembly, examine its types, and unload the assembly and its types? How to deal with similar tasks from the Net Framework now, in which it is necessary to download, examine and further unload assemblies, so that neither those assemblies nor their types remain in memory.

mshakurov avatar Jan 16 '24 18:01 mshakurov

I understand that you can use the launch of a separate application in which to do the work, get the necessary information, and hang that application. But to do this, you need to write a bunch of code, whereas AppDomain had convenient methods like CreateInstanceAndUnwrap.

mshakurov avatar Jan 16 '24 18:01 mshakurov