I am trying to instantiate a class from DemoClass.dll using Activator.CreateInstance(type.Assembly.FullName, type.FullName)
This class implements the one interface from other dll. Lets say DemoInterfaces.dll. Earlier it was supposed to implement two methods. But now we have only one method i.e. one is removed. However, while instantiating it is trying to reference old copy which I don't see anywhere. It is the new dll and also checked it in dotpeek. The DemoInterfaces.dll interface has only one method.
Below is the sample code.
Assembly assembly = Assembly.LoadFrom(path);
Type type = assembly.GetType("className", true, true);
xxx= Activator.CreateInstance(type.Assembly.FullName, type.FullName);
However, it is looking the implementation of second method. So Method implementation in class from DemoClass.dll is not found.
{"Exception has been thrown by the target of an invocation."} Data: {System.Collections.ListDictionaryInternal} HResult: -2146232828 HelpLink: null InnerException: {"Method not found: ''xxxx"} Message: "Exception has been thrown by the target of an invocation." Source: "mscorlib" StackTrace: " at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Bi nder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(String assemblyName, String typeName)\r\n at xxxx in xx" TargetSite: {System.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)}
Any help is highly appreciated.
Aucun commentaire:
Enregistrer un commentaire