cloudfoundry / dotnet-core-buildpack

Cloud Foundry buildpack for .NET Core on Linux
http://docs.cloudfoundry.org/buildpacks/
Apache License 2.0
91 stars 90 forks source link

Unable to install Dotnet: invalid character 'ï' looking for beginning of value #191

Closed Hobray closed 6 years ago

Hobray commented 6 years ago

What version of Cloud Foundry and CF CLI are you using? (i.e. What is the output of running cf curl /v2/info && cf version? 6.32.0

What version of the buildpack you are using? 2.1.4

If you were attempting to accomplish a task, what was it you were attempting to do? Push application to CF

What did you expect to happen? Successful push

What was the actual behavior? The following container compilation failure:

-----> Dotnet-Core Buildpack version 2.1.4
-----> Supplying Dotnet Core
-----> Installing libunwind 1.2.1
       Download [https://buildpacks.cloudfoundry.org/dependencies/libunwind/libunwind-1.2.1-4bc9ce84.tar.gz]
       **ERROR** Unable to install Dotnet: invalid character 'ï' looking for beginning of value
Failed to compile droplet: Failed to run all supply scripts: exit status 15
Exit status 223

Steps to reproduce the error

I have to preface this by stating that I know exactly what is causing the error and how to get around it but I struggled to find helpful documentation on the cause so I wanted to file this issue in case it can be resolved on the Cloud Foundry end. If it cannot, hopefully this documentation will keep someone else from beating their head against the wall like I did.

In my case, I had installed the dotnet core 2.1.301 SDK but still have applications that are targeting the 2.0 framework. While it may not always be necessary to force these older applications to build/publish using an older SDK version, a "global.json" file can be used to force the desired SDK version to be used. With that in mind, do the following to reproduce this error:

applications:

env: ASPNETCORE_ENVIRONMENT: Development

* The error details specified in the section above should be the result of this push

**The reason the push fails is because by saving the global.json file as UTF-8, a byte order mark becomes part of the file content and for whatever reason, this causes the CF build to fail.**

### Steps to work around the error
The easy solution to the problem I specifically outlined above would be to simply open the global.json file again in Notepad and save it using ANSI encoding as this will inherently remove the byte order mark.  After that, you can publish and push again and the container should compile properly.

If your certain that your global.json file no longer has a byte order mark and your push continues to fail with the same error message, here's another thing you can do to locate other possible problem files:

* Open an instance of Powershell
* Navigate to the folder where you published your code
* Define the function and run the command seen below to inspect all the files in the directory (and sub-directories) for leading byte order marks:
```powershell
PS C:\Code\Deploy>
>> Function ContainsBOM
>> {
>>     return $input | where {
>>         $contents = new-object byte[] 3
>>         $stream = [System.IO.File]::OpenRead($_.FullName)
>>         $stream.Read($contents, 0, 3) | Out-Null
>>         $stream.Close()
>>         $contents[0] -eq 0xEF -and $contents[1] -eq 0xBB -and $contents[2] -eq 0xBF }
>> }
PS C:\Code\Deploy> get-childitem . "*.*" -recurse | where {!$_.PsIsContainer -and $_.Length -gt 2 } | ContainsBOM

    Directory: C:\Code\Deploy

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2018   2:06 PM           1697 appsettings.CloudFoundry.json
-a----        7/10/2018   9:37 AM           1697 appsettings.Development.json
-a----        7/10/2018   9:37 AM            766 appsettings.json
-a----        7/10/2018   9:37 AM           1893 appsettings.local.json
-a----        7/10/2018   9:37 AM           1621 appsettings.Production.json
-a----        7/10/2018   9:37 AM           1652 appsettings.Staging.json
-a----        7/10/2018   9:37 AM           1648 appsettings.Test.json
-a----        7/10/2018   9:37 AM           1795 appsettings.UAT.json
-a----        7/11/2018   9:02 AM             80 global.json
-a----        7/13/2018   9:29 AM            447 web.config

PS C:\Code\Deploy>

As you can see, all of the appsetting documents, the global and even the web.config have byte order marks in this case. I ONLY needed to ensure that the global.json wasn't using a byte order mark to get my push to succeed. None of the other files mattered when it came to successfully pushing.

At any rate, this is a pretty slick way to identify any other possible stragglers that might have an impact.

Please confirm where necessary:

cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/159041833

The labels on this github issue will be updated when the story is started.

sclevine commented 6 years ago

This is now prioritized. Sorry for the delay.