Reputation: 9116
I have some ASP.NET application which composed of some modules. The web application has not direct reference to these modules. But in some part of its code it Loads those assemblies using following code in MyWebApplication.dll:
// modules: Module1 (Module1.dll), Module2 (Module2.dll), ...
foreach(module in modules)
{
Assembly.Load(module)
}
But when I'm running the application, it can't load the module.
To debug it, I checked where the other assemblies are located using:
typeof(SomeType).Assembly.Location
and the result was:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\99db3519\a290da98\assembly\dl3\b95f323e\b38a9c7e_53bdd001
In the following folder
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\99db3519\a290da98\assembly\dl3
there are the other assemblies each one in a separate folder. But it seems that ASP.NET brings just the required dll
files here. And it seems that it brings the assemblies that are referenced in some way from the WebApplication
.
Unfortunately my module assemblies are not referenced from WebApplication
as they're being loaded dynamically at run time.
Question: How can I say to ASP.NET to copy and bring my modules too, so I can load them at run time?
Upvotes: 0
Views: 156
Reputation: 100545
Unless you concerned with unloading assemblies use Assembly.LoadFrom
with full path.
To get full path in ASP.Net use Server.MapPath
(see following question to get correct arguments: Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference? ).
Notes:
Load
, LoadFrom
and LoadFile
have very subtle differences - when manually loading assemblies make sure to carefully read MSDN articles for corresponding methods, related question on SO like Difference between LoadFile and LoadFrom with .NET Assemblies? and Suzanne Cook's articles (not much changed with these methods since 2005).Upvotes: 1
Reputation: 635
You can create a folder in your web application called "DynamicReferences" and store a copy of each dll in that folder. Then for each dll in that folder set the Copy to Output Directory property to "Copy Always" or "Copy if Newer"
Upvotes: 0
Reputation: 1310
You can copy your modules to the project's bin directory in a post build event.
Upvotes: 0