Well, you can't add a reference - but you can just use Assembly.Load /
Assembly.LoadFrom to force loading a certain assembly. Alternatively,
you can handle AppDomain.AssemblyResolve or AppDomain.TypeResolve to
do a few things...
But first I'd try to figure out why resolution is failing... if the
dll isn't in the GAC, it must be part of the overall application "bin"
output.
Hi Marc,
My use case here will be .Net remoting, where the server is unable to
load assembly that wasnt reference during compile time.
the dll isnt in GAC, it is resided somewhere else, and i use
Assembly.Load to load it into the executing app domain. The assembly
loaded without issue.
Assembly someDllAsm = System.Reflection.Assembly.LoadFile(@"C:\SomePath
\SomeDll.dll");
AppDomain.CurrentDomain.Load(someDllAsm.GetName());
But when I have a client that call a method to the server using
remoting, exception was thrown with below stack:
System.IO.FileNotFoundException: Could not load file or assembly
'SomeDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or
one of its dependencies. The system cannot find the file specified.
File name: 'SomeDll, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
Server stack trace:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark,
Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.UnitySerializationHolder.GetRealObject(StreamingContext
context)
at
System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder
holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String
objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel
securityLevel)
at
System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack
sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders,
Stream requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
I am not too sure how AppDomain.TypeResolve works, I will try to look
into that after this. If you have any other thoughts, do let me know.
Thanks!
-chage