I'm working with assembly.CreateInstance, and it returns null, while it was fine using it with a different project with the same DLL file "assembly file", Can you please suggest reasons when and why it returns null?Please this is urgent??
Edit
The type I'm searching for has a default constructor, but it implements another interface, like this. Project1, has the interface A and makes the DLL which contains the new type let it be typeB which implements A. Project2, has the same interface A and use the "CreateInstance" method to locate the type typeB, but here the CreateInstance returns null, any suggestions?
I doubt it applies here, but there is 1 edge-case wher CreateInstance
returns null
(namely Nullable<T>
), and one extreme corner-case (ProxyAttribute
, discussed here) where a regular class can construct to null
.
But more likely:
as
, and the interface isn't implemented (perhaps the interface is declared in two different assemblies; it counts separately as different interfaces in each, even if the name and namespace are identical)From the edit, it sounds like the last point; you should have the interface defined once only, and a reference between assemblies so that other assemblies can see (and implement) that interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With