Probing the assembly from parent directory of the exe - c#

i have a folder structure as IntegrationClient\SampleClient\Client.Exe. I have created a folder DrawingClient with lot of thirdparty assemblies. For client.exe to find the assembly at runtime , i have used probing path as below and it works.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;DrawingClient;"/>
</assemblyBinding>
But if i need the client.exe to find the DrawingClient folder from parent directory ie under IntegrationClient\DrawingClient, can i achieve that by any means ? I tried using ..\DrawingClient however that failed.

Sadly, you cannot...
The MSDN Documentation states that privatePath [...] [s]pecifies subdirectories of the application's base directory that might contain assemblies. [...]

Firstly I'm pretty sure you have to use forward slashes rather than backslashes.
In addition to that you can chain your ../ lookups as far back up the directory tree you need to go
Example:
this ../ is the Parent Directory and this
../../ is the Grand-Parent directory and so forth...

Related

How to get path to solution directory from inside app.config

I have a file: AppSetting.config in the root folder of my solution.
In my projects App.Config I want to do the following:
<AppSettings file="<PathToSolutionRoot>\AppSetting.config />
Is there a way to get the <PathToSolutionRoot> somehow and stick it in the AppSettings so it points to the solution root folder?
From the documentation:
The path that is specified is relative to the local configuration file. The runtime ignores the attribute, if the specified file cannot be found.
So, this should work:
<AppSettings file="AppSetting.config" />
Now, if you run this in debug mode, it won't work. The reason is you need to add a post-build event so the appsettings.config file is copied to the bin\debug folder:
copy "$(ProjectDir)AppSettings.config" "$(TargetDir)AppSettings.config"
The double quotes are intentional as you may have spaces in the path.
So when you deploy your app, make sure you have this file copied to the root where the executable lives and it should work.

VS2010 DLLs not updating

I have a solution (ASP.NET, .NET 4.0) that doesn't seem to be updating its dlls properly. I noticed that, when I compile it after making changes, it doesn't see the additions that I've made.
I recently switched the targeted platform on the solution to x86, because we're now deploying it onto a x64 server and I am now maintaining it on a x64 Win7 machine. (I don't know if that might have something to do with it, see below.) After I isolated the problem, when I was testing, I found out that if I chose "view in browser" on one of the aspx files, it suddenly saw the changes that I had made earlier. I combed through the directories in the main project's bin folder, and I noticed dlls were being saved to two different places: the root of the bin folder, and bin/x86/debug/. The first location was getting updated when I simply compiled the solution, and the second was getting updated when I used "view in browser" on one of the aspx files.
Does anyone know of an errant setting which might cause this behavior?
Update: The answer provided by #Vinkal leads me to believe that Debug is looking at the bin/ folder for compiled code rather than bin/x86/debug/, where the code is being compiled to. Is it possible that could be the core problem?
I combed through the directories in the main project's bin folder, and
I noticed dlls were being saved to two different places: the root of
the bin folder, and bin/x86/debug/. The first location was getting
updated when I simply compiled the solution, and the second was
getting updated when I used "view in browser" on one of the aspx
files.
Check Configutation Manager as to what platform is selected as shown in the below screen shot#1.
Screen shot #1: Configuration Manager
if you create the new platform (here x86), Output Path is automatically set to bin\x86\Debug\. See the screenshot below.
Screen shot #2: Build Settings when Project Properties is selected
So when you compile the project, Binaries will be copied according to Output Path (here in my case, bin\x86\Debug\ for the Platform x86 which is set in Platform Target). Confirm as shown in the screen shot below, where all binaries are copied when you compile. As you have mentioned, when you compile the solution, Root of the bin folder is getting updated. So your project Output Path must be set to Root of the Bin folder for the whatever Platform (Any CPU, x86 or x64) you have set in Platform Target
Note: If Post-Build event commmand is set to copy Binaries, it will also be copied to the Path specified in Post-Build event command.
View in Browser: When page is opened using View in browser, page will again be compiled and Binaries are copied according to the Output Pathspecified in Project Properties as shown in the screen shot #2. As you have mentioned that bin\x86\Debug\ is updated when you view the page in Browser, it indicates that Output Path is set to bin\x86\Debug\ in your Project Properties, In the screen shot shown below, when page is opened using View in Browser, Binary is going to Bin folder and Platform is selected as Any CPU
Post-build event command: if you have also set the Post-build event command, as shown in the screen shot below, to copy the path in different location, in both the cases (i.e. when you compile and View in Browser), it will be copied to the Path specified in Post-build event command
EDIT:
As mentioned here, use the <probing> Element:
You can use the element in the application configuration file to specify subdirectories the runtime should search when locating an assembly. The following example shows how to specify directories the runtime should search.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
The privatePath attribute contains the directories that the runtime should search for assemblies. If the application is located at C:\Program Files\MyApp, the runtime will look for assemblies that do not specify a code base in C:\Program Files\MyApp\Bin, C:\Program Files\MyApp\Bin2\Subbin, and C:\Program Files\MyApp\Bin3. The directories specified in privatePath must be subdirectories of the application base directory
So in your case, modify the web.config as shown below
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin\x86\debug"/>
</assemblyBinding>
</runtime>
</configuration>
You might try to overcome this issue by changing different configurations in Tools -> Options-> Debugging -> Symbols

assemblyBinding probing is not working

Sorry if this question have been asked already. But I have two websites, One have already webconfig. and I have added other site directory as virtual directory inside first site.
Like below, SampleSite is the Site Name and I have added Sample as Virtual Directory from another location (c:\Sample). Now it has web subdirectory, in which Ver1.0 is another Site, which have its own dll and data.
Now I am launching SampleSite and after some event i want to launch Ver1.0 Site URL. When i launch Ver1.0 Site URL (localhost/SampleSite/Sample/web/VER1.0/default.aspx) then it gives me error of DLL function. That means DLL is not included here. So i added dll in Ver1.0 web.config as
<assemblyBinding xmlns="urn:Schemas-microsoft-com:asm.v1">
    <probing privatePath="bin/Sample.Web.dll;" />
</assemblyBinding>
Bin is in Ver1.0 folder, which have Sample.Web.dll
But still its showing me same error from DLL function. So please help me to resolve this functionality.
Note: I tried to make the Ver1.0 as Application Directory then its resolving the problem. But i want to make this dynamic. Because Ver1.0 could be any Site in future.
EDIT:
Adding Inside folder of Ver1.0, Bin has Sample.Web.dll, which i want to include.
According to documentation you should place all paths to subdirectories that should be considered by Fusion engine while searching for assembly inside privatePath attribute value.
If you want to probe for libraries that are placed inside Sample\web\Ver1.0\bin and Sample\web\Ver1.1\bin subdirectories it should be like this:
<probing privatePath="Sample\web\Ver1.0\bin;Sample\web\Ver1.1\bin" />

referencing dotnetnuke.dll from another folder on asp.net

I have dotnetnuke portal on server in /root/dnn and I am creating asp.net app in c# VS2008 that I need to upload on /root/app.
when I deploy my app, it needs to reference dotnetnuke.dll assembly from /root/dnn/bin instead of /root/app/bin.
how can I manage that, without putting app files in /root/dnn?
I tried to set auto-refresh path and then after upload deleting the /root/app/bin/dotnetnuke.dll so that the app tries to reference the missing assembly in ../dnn/bin/dotnetnuke.dll but the "application is not pre-compiled" error pops, so I tried to upload it without pre-compiling, but still the reference couldn't be found.
Why not give your app it's own copy? That would solve all problems...
In other words, why the cross-app reference? It goes against all security mechanisms of IIS and ASP.NET
As Purple Ant said above, either
load the DotNetNuke assembly into the GAC (which is troublesome because it precludes you from being able to XCOPY upgrade DNN later)
Put your app into the DNN application folder (sounds like what you did)
Copy the DNN dll into your app folder. (the most common solution)
What you're thinking of is the <probing privatePath="" /> element of the config file. But I don't think it's available to be used in web apps and (according to the documentation) only works for subfolders.
<configuration>
<runtime>
<assemblyBinding>
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
After all, I had to upload .aspx and .aspx.cs files in portal folder and bin files in dnn's bin folder, add the few lines from my web.config to dnn's web.config, and change queries to database by writing them from code instead using dataset objects, that is .xsd, .xss files. I also had to copy the code from my App_Code into my .cs files before upload because C# and VS cannot be compiled together in dnn's App_Code.
I think your best bet with what you are trying to do is to install the DotNetNuke.dll into the GAC on the server. I don't believe that ASP.NET/IIS will allow access to any assemblies outside of the current websites folder structure.

How come classes in subfolders in my App_Code folder are not being found correctly?

I am getting the following error when I put class files in subfolders of my App_Code folder:
errorCS0246: The type or namespace name 'MyClassName' could not be found (are you missing a using directive or an assembly reference?)
This class is not in a namespace at all. Any ideas?
You need to add codeSubDirectories to your compilation element in web.config
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="View"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
Check for BuildAction property of file. This should be set to "Compile"
Is it possible that you haven't set the folder as an application in IIS (or your web server)? If not, then the App_Code that gets used is that from the parent folder (or the next application upwards).
Ensure that the folder is marked as an application, and uses the correct version of ASP.NET.
It might not be the correct way but I find it the easiest.
Create the class in the main Folder as usual, then move it with your mouse to your sub-folder. Re-compile and all should be fine.
As you add folders to your app_code, they are getting separated by different namespaces, if I recall correctly, using the default namespace as the root, then adding for each folder.
In Visual Studio (2010 at least, but I recall past versions too), you can right click on the folder, within Solution Explorer, and then choose "Include in Project".
Then on the properties tab for each file (or select them all at once), you choose "Compile" for the "Build Action" property.
This worked for me.

Categories