Creating a virtual directory failed with the error
Asked Answered
M

21

103

I can't solve this problem

enter image description here

I suggest I have to change c:\Windows\System32\drivers\etc\hosts file and add after

# localhost name resolution is handled within DNS itself.

the next line:

127.0.0.1       mysite.dev

but it doesn't help. Any suggestions?

Error ocсurrs when I try to open web site project in Microsoft Visual Studio 2012.

Memo answered 29/8, 2012 at 2:33 Comment(2)
Check this: stonycreektechnologies.com/2011/03/15/…Inductee
It is second or third google link, I got while searched solution in the Internet. It's not what I need.Memo
M
38

I've already found the solution. I just had to edit C:\Users\Administrator\Documents\IISExpress\config\applicationhost.config file, by adding my site to <sites> node.

Memo answered 29/8, 2012 at 12:19 Comment(6)
In case this is not the answer for you and If you find yourself in my situation, I deleted the .vs directory to clear the cache and didn't notice that Visual Studio had changed my default build configuration to an auto-generated one that was configured to use IISExpress. So if you had a project that was working fine and then stops loading, I'd suggest before you do anything else to check the build config (which I of course failed to do)Forelimb
Oops, while my previous 'helpful' comment was accurate it was not the root cause of the cryptic error message. That would be the fact that the automatically recreated .vs folder inherited NTFS encryption. Back to normal without needing to edit the project file after decrypting that folder.Forelimb
Works even after 6 years. I got this issue with vs2017 latest version. But solved it using the above info.Grimbald
When does one use local applicaionhost.config vs the one in the solution folder?Shape
It didn't work for me. Since I was not interested in running or modifying the project, just opening it to look at the code (indeed I don't even have IIS installed on my PC), I copied it from the network drive where it was located to a local drive and it let me open it. I assume there is some trust setting that would get me there as well but could not figure out which one.Tail
Renaming the IISExpress\config folder then re-opening the project worked for me.Collyer
C
207

More often than not, at least in my case, this happens is when a *.csproj.user file is in the project directory and has <UseIISExpress>true</UseIISExpress> in it.

Alternatively, as mentioned by Zachary Cutler you can also simply: close Visual Studio, delete the *.csproj.user file and reopen Visual Studio. This will force VS to rebuild the file.

Cordiality answered 17/6, 2016 at 14:56 Comment(5)
this not work for me , after update vs2017 15.7.1 ,I got this problem.Wardlaw
This didnt work for me. I have deleted .vs folder. deleted *.csproj.user and still gives the same error.Shape
this also worked for me, I just deleted the [myproj].csproj.user file and it loaded - this was in VS2019 - running in admin modeSaimon
This was the answer for me. The disturbing thing is.. I already upvoted it. This answer is the gift that keeps on giving!Oxley
Visual studio 2022 'Creation of Virtual Directory Failed' was solved by this answer. unreal.Beloved
M
38

I've already found the solution. I just had to edit C:\Users\Administrator\Documents\IISExpress\config\applicationhost.config file, by adding my site to <sites> node.

Memo answered 29/8, 2012 at 12:19 Comment(6)
In case this is not the answer for you and If you find yourself in my situation, I deleted the .vs directory to clear the cache and didn't notice that Visual Studio had changed my default build configuration to an auto-generated one that was configured to use IISExpress. So if you had a project that was working fine and then stops loading, I'd suggest before you do anything else to check the build config (which I of course failed to do)Forelimb
Oops, while my previous 'helpful' comment was accurate it was not the root cause of the cryptic error message. That would be the fact that the automatically recreated .vs folder inherited NTFS encryption. Back to normal without needing to edit the project file after decrypting that folder.Forelimb
Works even after 6 years. I got this issue with vs2017 latest version. But solved it using the above info.Grimbald
When does one use local applicaionhost.config vs the one in the solution folder?Shape
It didn't work for me. Since I was not interested in running or modifying the project, just opening it to look at the code (indeed I don't even have IIS installed on my PC), I copied it from the network drive where it was located to a local drive and it let me open it. I assume there is some trust setting that would get me there as well but could not figure out which one.Tail
Renaming the IISExpress\config folder then re-opening the project worked for me.Collyer
O
20

You can opt to install IIS locally and edit a couple of tags on .csproj File. Open you csproj file and go to section <VisualStudio> then find tag <UseIIS>True</UseIIS> it must be set as true, then go to tag: <IISUrl> and set up with the URL address where the application will be hosted for testing:

<VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>True</UseIIS>
          <AutoAssignPort>False</AutoAssignPort>
          <DevelopmentServerPort></DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          **<IISUrl>http://localhost/myWebSiteAppSample</IISUrl>**
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>

And that is. Now you can load your project normally.

Obliteration answered 24/7, 2014 at 19:33 Comment(2)
Funny, this is the answer for my case.Usually
With a note: the ** asterisks should not be in the file. Of course.Twink
B
20

The problem would be your project setup to be executed in the local IIS and the URL specified not exist.

There are options you can do to fix the problem.

Option 1 : (Use IIS Express)

1.) Open you web project .csproj file as XAML or in notepad.

2.) Find these properties and set according to your preferences.

UseIIS = false

UseIISExpress = true

and that's it.

Option 2 : (Use local IIS)

Follow the option 1 steps but change the following properties.

UseIIS = true

IISUrl = https://localhost

UseIISExpress = false

Beverie answered 29/9, 2016 at 0:52 Comment(5)
Option 1 not WorkingArris
Option 2 worked for me, just had to set UseIIS = trueDesulphurize
Option 2 Worked :)Sage
I just had to set UseIISExpress = falseCarpenter
Wow. Both options worked like a charmAdelaideadelaja
J
11

The issue can be fixed by deleting the folder named .vs in the project directory.

This solves the problem because while opening the project after deleting the .vs file, it creates the same folder with subfolder config and folder with project name.

The config folder applicationhost contains the necessary settings required to run the project successfully.

Johnsten answered 11/4, 2018 at 18:29 Comment(0)
E
7

I just went to the directory named in the error and renamed the applicationhost.config and restarted and VS created a new file and ran fine.

Erect answered 30/4, 2018 at 14:12 Comment(0)
A
3
  • Tried several approaches mentioned in the answers, but what finally worked for me was swapping the <IISUrl> of .csproj with <CustomServerUrl>.

Edit :

  • The above didn't solve the root cause of the issue for me. However, If you've done a windows update recently, perhaps it might be the reason that's causing the issue. Try executing netsh http add iplisten 0.0.0.0 and see whether it solves the issue.

Hope these would help someone still looking for a way.

Article answered 8/8, 2019 at 10:52 Comment(1)
Of all the things (and I mean ALL), this (<CustomServerUrl>) is the one that finally did the trick for me. Thanks so much!Amnion
L
1

I don't know why, by my applicationhost.config file was completely missing from my C:\Users\Administrator\Documents\IISExpress\config\ folder.

Copy/pasting C:\inetpub\history\applicationhost.config into that folder seemed to fix the problem for me.

Got the idea from here.

Lindsey answered 13/10, 2015 at 20:51 Comment(1)
In my case file got corrupted. so I deleted it and replaced it with a applicationhost.config file found on system search. I don't have admin right so can't access inetpub\history. I think Visual studio always expects this config file but after that even though I deleted the applicationhost.config file repeatedly from IISExpress\config location VS kept on creating it. Looks like sometime settings gets corrupted but once it is inline with right settings VS takes care of all settings of its own.Reconnoiter
P
1
  1. Turn on windows features "Internet Information Services" in control panel.
  2. Open ".csproj" file and find
  3. Modify this line based on your requirements. http://localhost:777/
  4. Open the project/solution now
  5. If failed to load again, just right click the solution and select "Reload Project".
Phyla answered 21/4, 2016 at 3:25 Comment(0)
O
1

I know this is probably a rare occurrence, but figured I'd put it here:

My csproj file was set to "read only" (Don't ask me how I managed that), but after I turned off "read only" access, everything was fine. (VS2017)

Oosphere answered 14/12, 2017 at 17:21 Comment(0)
O
1

Not the exact same error, but I was lead to this answer since the first half of the error matched. Your applicationhost.config file may simply be read-only. Taking that off solved the error for me. That error calls out the file specifically though, so you should be able to find it easily.

Oulu answered 15/2, 2018 at 23:29 Comment(0)
L
1

I had to somewhat combine some of the above answers. My solution was to edit (not delete) the file .vs\config\applicationhost.config

There is a section for the bindings of the site, simply change from localhost to whatever you desire to run it under. Note that the port numbers are in front of the server name.

applicationhost.config bindings section

Lee answered 4/3, 2021 at 22:14 Comment(1)
Thanks a million - this solved my problem, too!Keto
L
1

I was able to resolve this by editing the file *.csproj in the root level of the project. I changed and from localhost to the site name as shown below. It may also be required to have the OverrideIISAppRootUrl set to True. enter image description here

Lee answered 8/10, 2021 at 15:59 Comment(0)
C
0

I was facing the same issue because of my network password changed.I changed my NetExtendor login password but I have to login in my laptop with old password.

Try these steps to fix this issue:

log into the Computer with whatever password works log into vpn with whatever password works ctl-alt-del to lock the pc then use the new password to unlock it

It worked for me :-)

Thanks!

Cryoscope answered 24/8, 2016 at 22:34 Comment(0)
O
0

My issue was with Windows 10 Defender. I had given IIS permission in the past, but seems like it is now ignoring it. Will look into it later, but for now I disabled controlled folder access and it worked.

Oldham answered 6/7, 2019 at 15:8 Comment(0)
B
0

I wanted open an exiting project of Visual Studio 2017 in VS 2019 and encountered with the same issue. I find its a version related problem. The solution is: Create a new project in the newer VS and copy the codes from the older VS.

Berwick answered 4/11, 2019 at 8:52 Comment(1)
Welcome to SO! In the question, there is no mention to any change on VS version. When you post an answer check that you are replying the question. If not, then just create a question with this issue and answer yourself, so it will help the Community.Hearst
C
0

Try decrypting the applicationhost.config file. That worked for me.

Crowe answered 15/5, 2020 at 17:20 Comment(0)
L
0

Creation of the virtual directory xxxx failed with error: Object reference not set to an instance of an instance of an object...

Error Screenshot This issue happened to me after deleting my local repository and downloading the repository from the cloud.

Per one of the solutions above, I deleted the .vs folder with no luck. To solve the issue, I ended up mixing a couple of the solutions in this forum.

I went to the folder .vs/SolutionName/config and pasted the applicationHost.config file from the latest subfolder on the folder C:/inetpub/history/

After that, I restarted VS and the error disappeared.

Lyonnaise answered 15/9, 2021 at 21:16 Comment(0)
B
0

simply fix for me
Close your Visual Studio

o remove .vs in .Net
o remove IISExpress in Documents

Reopen it, everything should be fine

Beachcomber answered 11/2, 2022 at 3:28 Comment(0)
E
0

Thanks to @saminpa, I found this comment helpful in my situation, so, I added it as an answer to be found easily.

If the .vs folder is encrypted by the NTFS encryption system (EFS), this error will be seen.

Engineering answered 31/10, 2023 at 11:57 Comment(0)
C
-1

So here are the steps to fix it:

  1. Go where your .csproj file is. This is usually one directory below the solution (.sln)
  2. Right click and open with a text editor (notepad)
  3. Find IISUrl tag and replace its content for http://localhost:(YourPortNumber)
  4. Save and reload your project!
Caswell answered 20/3, 2019 at 17:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.