45

When I create new ASP.NET 4.5 web forms application from vs2012 and update all nuget packages, I receive this error on build:

Error 1 The "EnsureBindingRedirects" task failed unexpectedly. System.NullReferenceException: Object reference not set to an instance of an object. at Roxel.BuildTasks.EnsureBindingRedirects.MergeBindingRedirectsFromElements(IEnumerable`1 dependentAssemblies) at Roxel.BuildTasks.EnsureBindingRedirects.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext()

Kos
  • 3,847
  • 8
  • 29
  • 34
Ivan Lewis
  • 720
  • 1
  • 7
  • 18

14 Answers14

65

It's a bug in Microsoft.Bcl.Build and to solve it you have to put culture info in the assemblyIdentity-part of web.config or app.config.

For example if you have:

<dependentAssembly>
   <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
   <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>

change it to:

<dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Kos
  • 3,847
  • 8
  • 29
  • 34
Henrik Fransas
  • 1,025
  • 10
  • 15
17

I had this error but slightly different, took me 45 minutes to figure it out so thought I'd better get this out there.

Was experiencing the "EnsureBindingRedirects" task failed unexpectedly problem but mine came from an XmlException:

(...)\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets(97,5): error MSB4018: System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'. Line 39, position 175.

Turns out the cause was that I'd recently added an entry to my web.config's appSettings where the value was a URL that contained an ampersand (&).

Ampersands need to be escaped in XML, even in attribute values.

I changed all the & in the URL value to &amp; and it built without issue.

Kos
  • 3,847
  • 8
  • 29
  • 34
JHo
  • 426
  • 4
  • 6
12

In my case issue have revealed after I merged a branch which broke my web.config file. It added comment character sequence <!-- without closing part -->.

Making file markup valid fixed the issue.

Kos
  • 3,847
  • 8
  • 29
  • 34
Vova Bilyachat
  • 15,962
  • 4
  • 48
  • 72
  • Thx! This was the cause here too. I would probably not have discovered it without your comment, since the error was in the Web.config file and not the *.csproj file that I thought it referred to. You learn something new every day ;) – user2890488 May 04 '17 at 11:53
  • 1
    I also had a corrupted web.config. Once fixed, project compiled – pat capozzi Jan 15 '20 at 00:03
10

Update Microsoft.Bcl.Build to fix this.

Run this on Package Manager console:

Update-Package Microsoft.Bcl.Build
Kos
  • 3,847
  • 8
  • 29
  • 34
Akira Yamamoto
  • 4,196
  • 3
  • 39
  • 41
1

A new version of Microsoft.Bcl.Build (1.0.6) has been pushed up to NuGet.org to fix this problem. The workaround to add the culture to the assemblyIdentity is no longer necessary but won't hurt if you leave it in.

Ron Cain
  • 101
  • 2
  • 5
    I tried 2 days back, it still breaks. Dunno which parallel universe this new package is in! :) – Mrchief Apr 07 '14 at 15:52
1

The following steps can be performed to solve the issue:

  1. Update the "Microsoft.Bcl.Build" package to the latest version.
  2. Make sure you have an App.config/Web.config file under your project and it also exists physically in a relevant folder on your machine.
  3. Make sure there are no special characters in the App.config/Web.config file. If they exist you need to replace them. Look at this article -> https://support.crossref.org/hc/en-us/articles/215652783-Special-characters-in-your-XML
  4. In App.config/Web.config file under each <dependentAssembly> add the following key-value pair: culture="neutral" to <assemblyIdentity ... />.
  5. Another step that describes how to fix your unique case and has been not described above :)

I hope this helps.

Denys
  • 33
  • 5
0

You have added a reference of a file which actually doesn't exists in your solution folder.

user761276
  • 11
  • 1
0

This happened to me when I had a BIN and OBJ folder marked read only. Remove the read-only on *.dll.config and *.app.config or delete those folders.

Eric
  • 116
  • 1
  • 3
  • 9
0

My problem was that the tag was not on the first line of the file. Fixed that and everything worked ok.

0

My problem was due to an appSettings value in web.config which contained a url with a & character.

Shane Courtrille
  • 13,432
  • 19
  • 69
  • 110
0

For me it happened because App.Config wasn't in the folder and there were other app.configs meant for different env. So I copied it.

C.P. Soni
  • 31
  • 1
0

I had a similar issue but mine was caused by having xml transform directives in web.config

Error The "EnsureBindingRedirects" task failed unexpectedly. System.Xml.XmlException: 'xdt' is an undeclared prefix. Line 27, position 59. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg, Int32 lineNo, Int32 linePos)

I had copied and pasted an appsetting from one of the transforms. The solution was to remove the transform attributes

(granted this is not the exact issue the OP had, but could help someone else)

0
I resolved this by following these steps:

1.) Delete Microsoft.Bcl.Build.1.0.13 from solution\packages.

2.) After it Closes the solution, then open the solution.

3.) Navigate to tools/Nuget package manager.

4.) Press Restore Packages in right top corner of the window, after it Re-build the solution.

0

In general it's Microsoft.Bcl.Build failling. In my case was after a merge and Git add invalid data to my web.config. Just open the web.config file and check for lines like this:

  • <<<<<<< HEAD
  • =======
  • >>>>>>> dev

Remove them.

Carlos Toledo
  • 1,914
  • 17
  • 22