Reputation: 181074
I have two assemblies, created through conditional compilation (dev and real).
The public surface of these assemblies is 100% identical: both are strongly named; both are signed with the same .snk
and therefore have the same PublicKeyToken
; both have the same culture and the same version. I cannot change this: making them appear identical is the whole point.
However, on my machine the real assembly is in the GAC. I have an ASP.NET 3.5 WebForms app that references the dev assembly. It absolutely must do that; the real assembly crashes the app.
Is there a way to force a specific ASP.NET application to use the dev one (which is in /bin
), given that:
Version
and PublicKeyToken
.I noticed that someone already asked this in #991293, but the accepted answer involved removing the signing, which isn't an option here.
Am I out of luck?
Upvotes: 30
Views: 22718
Reputation: 347
I found another way. It is only meant for developers, but it works. According to https://msdn.microsoft.com/en-us/library/cskzh7h6(v=vs.100).aspx you set this in the your .config file
<configuration>
<runtime>
<developmentMode developerInstallation="true"/>
</runtime>
</configuration>
You also need to set the Environment variable DEVPATH with to the path of your dll. Open a cmd, set the variable, run your app:
SET DEVPATH=YOURLOCALPATH
This helped me to load a local Oracle.ManagedDataAccess.dll since Oracle releases new versions, but they all have the same Version and PublicKeyToken. Thanks Oracle!
You can use Process Explorer from Microsoft to see the difference. See https://technet.microsoft.com/en-us/sysinternals/
See this as a small proof of concept:
Upvotes: 6
Reputation: 34421
You'd have to do something like manually loading the assembly from the file (Assembly.LoadFrom
, or Assembly.Load(byte[]
) ) before it is loaded from the GAC, and then handle the AppDomain.AssemblyResolve
event. Check out Suzanne Cook's blog post for more details.
Upvotes: 0
Reputation: 17190
It is possible, but it is advanced and require your knownledge on CLR and how it works and C++.
Take a look at this google book:Customizing the Microsoft® .NET Framework Common Language Runtime
Keywords: IHostAssemblyManager, IHostAssemblyStore
Upvotes: 6
Reputation: 26329
GAC is always tried first, when binding assemblies: How the Runtime Locates Assemblies
So no, you can't do this. However if you explain why you have such strange requirements there might be a different work around, you have not thought of.
Upvotes: 15
Reputation: 755387
No there is no way to do this. When loading an assembly the CLR will check to see if a DLL with an equivalent strong name is present in the GAC. If there is a matching assembly in the GAC it will pick the GAC assembly every time. There is unfortunately no way to override this behavior.
Upvotes: 14