Create new AppDomain in my azure function
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
I need to run some code in a new app domain. So I am trying to create an instance of my object in the new app domain... Here te code I am using:
```
public static class Program
{
private static ITemplateEngineProvider _templateEngineProvider;
static Program()
{
AppDomain ad = AppDomain.CreateDomain("New domain");
ObjectHandle handle = ad.CreateInstance(
assemblyName: typeof(RazorTemplateEngineProvider).Assembly.FullName,
typeName: "RazorTemplateEngineProvider"
//ignoreCase: false,
//bindingAttr: BindingFlags.CreateInstance,
//binder: null,
//args: new object[] { new string[] { templatePath, layoutPath } },
//culture: CultureInfo.InvariantCulture,
//activationAttributes: null
);
_templateEngineProvider = (RazorTemplateEngineProvider)handle.Unwrap();
}
}
```
`RazorTemplateEngineProvider` is a custom public class that has a public constructor. It has been implemented in a class library (`MyCustomLib.dll)` I referenced inside the azure function. The class implements an interfaces defined in another class library (`IMyCustomLib.dll`) referenced only by the previous class library, not by azure function.
At the moment there is no code inside the RazorTemplateEngineProvider class:
```
public class RazorTemplateEngineProvider : MarshalByRefObject, ITemplateEngineProvider
{
public RazorTemplateEngineProvider()
{ }
}
```
When I try to do `ad.CreateInstance` a `FileNotFoundException` has been thrown:
> Could not load file or assembly 'MyCustomLib.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.
But the file exists and it should be already correctly loaded... Infact if I run this 'query'
```
IEnumerable loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => !a.IsDynamic && !a.FullName.Contains("Version=0.0.0.0") && File.Exists(a.Location) && !a.Location.Contains("CompiledRazorTemplates.Dynamic") && a.FullName.Contains("My"))
.Select(f => f.FullName)
.ToArray();
```
I think problem is azure because I copied and pasted my code in a console application and thereit works.
I see both my dll. So, why do I get that error?
Thank you
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.