CreateInstanceAndUnwrap fails to load assembly in new appdomain

0

We were facing some issue while loading assembly in new app domain by using createInstanceFromUnWrap method.

I added actual code & inner exception message for this issue (PFB). But we suspected this error is not related to assembly loading method.Kindly let me know how to get exception for appdomain create instance and also resolution for this issue.

var domainSetup = new AppDomainSetup   {
            CachePath = cache,
            ShadowCopyDirectories = drivers,
            ShadowCopyFiles = "true",
            ConfigurationFile = 
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
            ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
        };

domain = AppDomain.CreateDomain(domainName, 
AppDomain.CurrentDomain.Evidence, domainSetup);

Drivers = (T)domain.CreateInstanceFromAndUnwrap(dllPath, typeof(T).FullName);

ERROR YYYYYYYY Error Exception:System.TypeInitializationException: The type initializer for 'NLog.LogManager' threw an exception. ---> System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401) at NLog.LogFactory..ctor() at NLog.LogManager..cctor() --- End of inner exception stack trace --- at NLog.LogManager.GetCurrentClassLogger() at YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY..ctor()

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName, Object[] activationAttributes) at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName) at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName) at YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY`1..ctor() at YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY(String tempDir) at YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY.YYYYYYYY(Stream package)

c#
mef
appdomain

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0