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
Related
I'm working in a legacy project (Windows Forms Application), with target framework .NET 2.0. The goal is to build a single .exe file that does not depend in any configuration file (in particular that does not depend on the .exe.config because the application doesn't need anything from this configuration file).
The characteristics of the project:
Application:
Targe framework: .NET Framework 2.0
Output type: Windows Application
Auto-generate binding redirecs: Not enabled
Build:
Platform target: Any CPU
Visual Studio Community 2019, version 16.1.3
The solution has a app.config file that I've tried to remove but for some reason It seems that remains in the project. When I say seems to remains in the project is because I follow this steps:
In the Solution Explorer, right-click on the App.config, and then click on Exclude From Project.
Rebuild the project, and still the .exe.config in generated.
Again in the Solution Explorer > Add > New Item, and when I try to add an Application Configuration File with the name App.config VS show this message: A file with the name 'App.config' already exists. Do you want to replace it?.
(I've also tried with the right-click on the App.config, and then click Delete option)
This seems to indicate that the configuration file is not effectively removed from the project, and therefore the .exe.config is still generated.
Also, I've checked this post, and tried changing the files properties (Build Action, Copy to Output Directory, etc) but the .exe.config file remains in the build.
Finally, I've tried (probably more as a desperate attempt) with uncheck the Auto-generate binding redirects which prevents the generation of the .exe.config but the .exe is not running properly.
Just as an additional information, the content of the .exe.config is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Company.Afis.ImageContainer" publicKeyToken="97cac07b8409e999" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.0.1827" newVersion="2.5.0.1827" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Other post that I've checked:
How to make work 'do not copy' app.config to output directory?
appname.exe.config not created on windows application
Release build without config file
How to not copy app.config file to output directory
If any other information is needed, please let me know to update it.
Disable auto generation of assembly binding redirects and instead, handle AssemblyResolve event of the current AppDomain.CurrentDomain and load the requested assembly in the event handler.
Disable Auto-generate assembly binding redirects
Right click on project, choose Properties and in the project properties page, in the first tab (Application tab), uncheck Auto-generate binding redirects. You can do the same by editing project file and setting <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>.
Handle AssemblyResolve Event
You should add the event handler before the run-time tries to load the assembly. For example, in the static constructor of Program class. For example, in the following code, I suppose the application is looking for MyAssembly which I have it as MyAssembly2.dll in application's folder.
static Program()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private static Assembly CurrentDomain_AssemblyResolve(object sender,
ResolveEventArgs args)
{
if (new AssemblyName(args.Name).Name == "MyAssembly")
return Assembly.LoadFrom(
Path.Combine(Application.StartupPath, "MyAssembly2.dll"));
throw new Exception();
}
In one of my ASP.NET apps, all of a sudden I am unable to run it in Visual Studio 2013 due to the error displayed below. It appears that it is trying to open the web.config from a path that doesn't even exist. All of my project code, including web.config, are located under C:\Projects\SourceCode\AFEManager\Trunk\AFEManager.Web. I've found a number of posts here from users experiencing a similar error, but the solutions seem to vary and none I've found so far seem applicable to my situation. I looked in that TraceLogFiles directory and the most recent log file there is five days old so it obviously hasn't been logging anything since I've been having this issue. Any suggestions are appreciated.
In my case I deleted all folders in D:\My Documents\My Web Sites\ before
Then I caught the error
There is a file .vs\config\applicationhost.config in my solution folder
It contains reference to the deleted folder. So, I deleted applicationhost.config and then pressed 'Create Virtual Directory' button in my project property Web page. It was recreated the file and the folder
I've been able to resolve this issue even though I can't say I fully understand all of the details. I'll attempt to describe the situation the best I understand it and hopefully others with greater insight can add further clarification.
After having been doing all of my development on my workstation, it was suggested that I begin doing this work in a new VM environment that had been set up for me. So I installed VS 2013 there and copied my source code from various projects over there. However, rather than follow my previous local path convention of C:\Projects\SourceCode[ProjectName]... this time I decided to use the directories that are set up during the VS install, c:\users[MyUser]\My Documents\Visual Studio 2013\Projects[ProjectName]. Sometime shortly thereafter, our infrastructure team made a change so that my home directory, c:\users\rmayer, was now being pointed to a common network drive, \totalsafety\TSUsers\rmayer. Everything continued to work without any issues.
However, due to various difficulties I had working in this VM environment, I decided to return to doing my development work on my workstation using the original local paths for my source code. This is when I began encountering the errors described above whenever I would try to run my code through VS. What I've begun to learn is that there is an applicationhost.config file that IIS Express uses located here: \totalsafety\TSUsers\rmayer\My Documents\IISExpress\config. It contains entries for each of my web projects; the one relevant to this issue had a section which looked like this:
<site name="AFEManager.Web-Site" id="8">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\rmayer\Documents\My Web Sites\AFEManager.Web-Site" />
</application>
<application path="/AFEManager" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\SourceCode\AFEManager\Trunk\AFEManager.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:19257:localhost" />
</bindings>
</site>
The physical path attribute listed under applicationPool="Clr4IntegratedAppPool" at that time was set based on the local path I had been using at the time I was working in the VM environment. Now that this one file is being shared regardless of whether I'm working locally or within the VM due to the move of the users' home directories, this path is invalid when I'm working from my workstation. By updating this path to C:\Projects\SourceCode\AFEManager\Trunk\AFEManager.Web, it now works correctly from my workstation.
Again, I have a limited understanding of how this is supposed to work, but what it's telling me is that I will be unable to do development work from multiple environments (not that I want to any longer) unless the local paths are consistent between all of them. If I'm correct about this, this seems like a less than ideal design.
I had this issue when I moved the project folder to the new machine. The problem is that the VS has the site registered in its config file (applicationhost.config) inside .vs/ folder but did not create folder inside %USERPROFILE%\My Documents\My Web Sites\. If you just click Create Virtual Directory inside the project properties (Web tab) it will not be enough.
First close your VS and remove .vs/ folder inside your solution directory
Reopen VS and click Create Virtual Directory inside the project properties (Web tab) - VS will register the site again and create corresponding folder inside %USERPROFILE%\My Documents\My Web Sites\
I changed the virtual directory path in vs\config\applicationhost.config inside the solution folder.
In my case, the project was located on network not my local disk. After copying the project to local, the issue was resolved. Hope it can save someones time who has the same issue.
You can change the path for the web.config to its real path in applicationhost.config file. This file is located in /.vs/config folder.
After changing the path in this file, save it and restart the project, it solved my issue.
This is happening because I have different work stations, but the project is saving in different folders.
Delete .VS folders that Visual studio created.
It might be hidden in your project structure.
Unhide the folders and look for .vs folder and delete that folder and rebuild the application.
Most simplest way to solve this issue.
Approximate reason to arise this error is copy project from another pc.
Solution:
Step 01: From Visual Studio Solution Explorer, Right click on your project and choose Open Folder in File Explorer.
Step 02: Open .vs folder (Hidden Folder) and
you will get 2 folder named config and another one is named as
your_project_name/config.
Step 03: Both config folder will contain a
file named applicationhost.
Step 04: Open both applicationhost file using notepad and find the directory showing in error screen (Config
File \?\C:\User\hp\Documents\My Web
Sites\YourProjectName\web.config)
Step 05: Just replace this
directory according to your pc directory. Example, in my pc I have
changed as below:
C:\Users\Sydur Rahman\Documents\My Web Sites\MyProjectName-Site
to
C:\Users\hp\Documents\My Web Sites\MyProjectName-Site
Note: Please make sure you have changed in both applicationhost file.
That's all. Now your project will run as expected!
Thank you PongGod!! I am not able to comment on your answer but I wanted to post anyway since I had the exact same issue while running an instance of Orchard. In my case, everything had been running great until I found a bunch of old project files located in:
%USERPROFILE%\My Documents\My Web Sites\
And started deleting them for no apparent reason. I then tried to start up Orchard from Visual Studio in debug mode and received the error message above. After applying the same fix to my applicationhost.config file, everything is working fine now.
In my case, I am assuming that the directories got mixed up because I had initially ran the default Orchard files from Visual Studio and from Web Matrix. Then later on, I downloaded the full source files and began running the files from a completely different directory. Thanks again.
Here is a solution i have found.
https://gyorgybalassy.wordpress.com/2015/03/06/i-asked-for-a-vs-folder-and-the-vs-team-gave-it-to-me/
(1)Find the applicationhost.config file in |YourSolution|\.vs\config
(2)Modify the VirtualDirectory PhysicalPath To your project.
(3)Restart solution. Start project.
(4)If it's still not working, try to check setting in your IISExpress config. If there is not site setting, copy And paste the setting to |UserOnYourComputer|\Documents\IISExpress\config\applicationhost.config
(5)Change the id to other id which not be used in IISExpress applicationhost.config.
(6)Start your project.
I experienced the same issue and I resolve it quite simply. My issue was arose after when I perform a merge operation in git repository, after merge operation Visual Studio some how changed my default project URL to the default URL of my partner's computer from where he pushed the last time in to my repository.
So here is how I resolved this error:
Simply go to the properties of the project.
From the left vertically aligned menu, select Web.
After you will Project url and a text box containing the default port number, now just aside that textbox there is a button "Create Virtual Directory".
Press that button and there you go.
It will again point the default url the current working folder of your project.
Hope it works for you all :)
After all this answers I find my solution. Delete te WebSite in the IIS and recriate. Why? Because I had create de website before installed the framework 4.5 and URL Rewrite.
Go to the project dir:
..\\{ProjectDir}\\.vs\\{ProjectName}\\config
Then delete the applicationhost.config file and recompile your solution.
That's all.
This steps helped me to get over this error
1.In Windows Explorer, locate the web.config file that is associated with the Web site.
2.Right-click the web.config file
3.Click Properties.
4.Click the Security tab, and then click Edit.
5.Click Add.
6.In the Enter the object names to select box, type computername\IIS_IUSRS, click Check Names, and then click OK.
Note* Computername is a placeholder for the computer name.
7.Click to select the Read check box, and then click OK.
8.In the Web.config Properties dialog box, click OK.
I'm working with Visual Studio 2012 and MVC4. I've added a linked file (from another project) to my MVC4 application. Here are the properties of the file:
Build Action: Content
Copy to Output Directory: Do not copy
Here is an example of my bundle:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive*","~/Scripts/jquery.validate*","~/Scripts/FolderA/*.js"));
For testing, I've also added an empty JavaScript file (temp.js) to that folder. This is not a linked file. When inspecting the source of the page this file appears but the linked file does not. I cannot navigate directly to this file either. The other files in the bundle appear just fine.
Can linked files be bundled?
Short answer: No in debug mode, yes in release mode.
File linking is a Visual Studio concept used to include files stored elsewhere into code and resource compilation. Clearly, linking a file will work if you need to compile it (it's a source file), if you need to embed it as a resource or you need it copied to target directory (if Copy to Output Directory is set to Copy).
Why it doesn't work in debug mode
In debug mode, bundling is disabled and scripts are linked to individually. Since files are not copied to root of your web application, they will not be accessible to user through IIS. If you try to enable copying of the script file every time you build the application, file will be copied to bin directory of web application. This directory is not accessible through IIS, and again this won't work.
Why it works in release mode
In release mode, bundling of scripts is performed. Script files are not linked to individually from web pages, and therefore user does not need to have access to them directly. Only bundling code needs to be able to access it. But you have to be sneaky about configuring this. You need to:
Set Copy to Output Directory of linked scripts to Copy always. If you store your linked scripts in ~/Scripts, once you compile the application they will be copied to ~/bin/Scripts folder.
Configure bundling path to include bin directory.
Note ~/bin/Scripts/ in following line:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive*","~/Scripts/jquery.validate*","~/bin/Scripts/FolderA/*.js"));
Disabling debug mode
Debug mode mentioned here is not compiler setting in Visual Studio. This is an element in web.config file.
<system.web>
<compilation debug="false" targetFramework="4.5" />
The easiest solution I've found to get bundling to work with linked files is adding an MSBuild target which automatically copies any linked content files to the correct location before every build.
Simply add the following to the [project].csproj file:
<!-- Copy linked content files to their location on build. -->
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
</Target>
This allows me to link Angular JavaScript files, Bootstrap CSS files etc. from their NuGet packages without having to commit them to source control or breaking bundling.
I have a c# .net app.
I'm using a WebKitBrowser.
The problem is that the app does not work if i don't put all the webkit DLLs into the debug/release folder.
What i'm trying to do, is to put all these files into a folder like debug/WebkitFiles and all the files to be token from there.
Any help? thanks
This should help:
<probing> and <privatePath>
Read up on the <assemblyBinding> tag in MSDN as well:
Note the changes go into your app.config file.
You can xcopy the files in your post-build event, under the project properties
Additionally, how did you first referenced the WebKitBrowser DLLs?
If you expect .NET do bind to an assembly but it is failing, do the following:
1. Open the Visual Studio Command Prompt
2. Type 'fuslogvw'
-- every load of an .NET assembly will be registered in the console
Put your DLLs where you want then add a reference to them and set "copy local" to true. If you want to keep dependencies in a sub-folder you have to modify your assembly manifest file.
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.