Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio debugger assembly binding failure with EnvironmentConfigBuilder #129

Open
turbodrubin opened this issue May 13, 2020 · 6 comments

Comments

@turbodrubin
Copy link

turbodrubin commented May 13, 2020

There's an assembly binding error that occurs when debugging my ASP.NET MVC application (.NET Framework 4.7.2) in Visual Studio 2017:

image

The following error occured [sic] while getting connection string information from the configuration file.
"An error occurred loading a configuration file: Could not load file or assembly 'Microsoft.Configuration.ConfigurationBuilders.Environment' or one of its dependencies. The system cannot find the file specified. (C:\...\Web.config line 20)"

My web.config file contains:

<configBuilders>
  <builders>
    <add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </builders>
</configBuilders>

<connectionStrings configBuilders="Environment">
  <add name="PrimaryDatabase" connectionString="" />
</connectionStrings>

My application does run as expected, and the configuration builder does behave as expected, but it is troublesome to debug in Visual Studio.

Using the Fusion Log Viewer, I tracked down this binding failure:

*** Assembly Binder Log Entry  (5/13/2020 @ 3:17:00 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Configuration.ConfigurationBuilders.Environment
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.Configuration.ConfigurationBuilders.Environment | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\DavidRubin\AppData\Local\Microsoft\VisualStudio\15.0_073ea14d\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PublicAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PublicAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PublicAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PublicAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/TestWindow/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.Configuration.ConfigurationBuilders.Environment/Microsoft.Configuration.ConfigurationBuilders.Environment.EXE.
LOG: All probing URLs attempted and failed.

I was able to work-around by copying Microsoft.Configuration.ConfigurationBuilders.Base.dll and Microsoft.Configuration.ConfigurationBuilders.Environment.dll to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PublicAssemblies but this is unsatisfying.

Is there a more-official solution?

@StephenMolloy
Copy link
Contributor

In the ASP.Net scenario, we had to add a little bit of magic to make the ConfigurationBuilder feature work in the .Net framework. When a classic ASP.Net web application runs, it does not run in the default app domain. Instead, ASP.Net spins up a new app domain in the process and starts the application there. But in doing so, ASP.Net reads some configuration settings before spinning up the AppDomain so it can set certain flags on the domain it creates. The problem is, the default domain isn't using the bin path that the new domain will be using. So any config builders you have in your bin folder won't be found. If they're in the GAC or the normal search path for the hosting process they will be found.

The decision was made to run the config builder if it could be found, but to continue gracefully if it couldn't be found - only in this ASP.Net pre-AppDomain loading peek at the web.config. So we swallow the not found exception and go on. If you're debugging with all first-chance exceptions enabled though, you'll hit a break in this case. :/ Really the only "workarounds" are to put the config builder dll's somewhere they can be found.

@turbodrubin
Copy link
Author

Thank you, @StephenMolloy for the interesting explanation. Are there any Visual Studio Components, Workloads, or Extensions that you're aware of that would place any/some/all of the ConfigBuilders in "findable" locations?

@jmguazzo
Copy link

I had the same issue as this one and the solution I found to avoid the "loading configuration error" is to place the configBuilder in another assembly/dll, outside the aspnet project.

@bartlomiejmucha
Copy link

@StephenMolloy
I had a similar issue and I fixed it by adding <probing> element to the Web.config like that

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="bin"/>`

So I literally pointed to the bin folder.

@Seabizkit
Copy link

Seabizkit commented Oct 21, 2021

ms come on fix this, ppl still need old stuff supported.

@StephenMolloy
Copy link
Contributor

Having re-read the description of this problem more closely, I am inclined to believe this is an IDE/tooling issue. It looks like VS is doing some independent processing of config for the app. This is probably better addressed with the VS team as it's not really the responsibility of nuget packages to unilaterally install themselves into directories that are not part of the application they are installed in. Feedback for VS2017 can be submitted as described here: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-report-a-problem-with-visual-studio?view=vs-2017

However, I was not able to reproduce this error in my attempts on VS2017 or VS2019. There must be a missing step in there that triggers the IDE's independent processing of config that is left out of the repro description. If anybody has more complete repro steps to share, that would help in identifying the issue and whether there are any potential solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants