The GenerateBlazorBootJson target may show a "Specified cast is no valid." error, causing Blazor builds to fail. It's not clear where the actual error occurs, but it's also not very actionable to the user.
In my particular case, the problem was solved by removing the com.apple.quarantine file attribute.
The build should succeed, or the error should be actionable.
The build fails as described above.
If you run xattr * inside the directory, you will see the culprit:
> xattr *
nuget.config: com.apple.quarantine
SwitchStream.Client: com.apple.quarantine
SwitchStream.Server: com.apple.quarantine
SwitchStream.sln: com.apple.macl
SwitchStream.sln: com.apple.quarantine
macOS has applied the com.apple.quarantine attribute to the directories, limiting MSBuild's abilities.
Now, remove this attribute recursively _inside the directory_ (don't do this to your entire Downloads folder):
xattr -dr com.apple.quarantine .
…and build again. The build will succeed.
VS4Mac 8.5, Blazor 3.2p3
> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.201/
Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8
.NET Core SDKs installed:
3.1.201 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Unfortunately, I spoke too soon, and the issue reappears after a rebuild.
A more or less empty blazor.boot.json gets generated:
{
"cacheBootResources": true,
"config": [ ],
"debugBuild": true,
"entryAssembly": "SwitchStream.Client",
"linkerEnabled": false,
"resources": { }
}
Thanks for contacting us.
Can you please share the full exception details (including the stack trace)?
Can you also confirm, whether this works when you run it from the command line?
There is no stacktrace (or I wouldn't know how to get to it), because the exception is raised by MSBuild. With MSBuild set to detailed, here's the output for that particular target:
Target _GenerateBlazorBootJson:
Building target "_GenerateBlazorBootJson" completely.
Output file "obj/Debug/netstandard2.1/blazor/blazor.boot.json" does not exist.
Task "GetFileHash"
Done executing task "GetFileHash".
Using "GenerateBlazorBootJson" task from assembly "/Users/chucker/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.0-preview3.20168.3/targets/../tools/netfx/Microsoft.AspNetCore.Components.WebAssembly.Build.Tasks.dll".
Task "GenerateBlazorBootJson"
/Users/chucker/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.0-preview3.20168.3/targets/Blazor.MonoRuntime.targets(348,5): error : Specified cast is not valid.
Done executing task "GenerateBlazorBootJson" -- FAILED.
Done building target "_GenerateBlazorBootJson" in project "SwitchStream.Client.csproj" -- FAILED.
And here's the entire output.
Can you also confirm, whether this works when you run it from the command line?
Looks like it does work, _if_ I explicitly clean first. If I don't and simply dotnet run, it seems to assume the project has been built correctly.
But if I do dotnet clean; dotnet build; dotnet run --project SwitchStream.Server, I do not get an error, and the web server launches. And blazor.boot.json now contains a non-empty listing of resources. I've added the detailed build output of that (dotnet build -v d) to the same gist.
@chucker thanks for the details.
@pranavkm this seems like something VS 4 Mac specific. I can think of two things:
same issue occurs
@sayedihashimi can you help us out with the above investigation? This seems to be VS 4 Mac specific and we don't know what's the reason. let me know if you want me to move this to some other repo.
Thanks, I was able to reproduce. I have created an internal ticket to track this on our side.
@mkArtakMSFT please assign this to @rodrmoya (I don't have permission to change it myself).
Indeed, was looking at this same issue (see this internal ticket) but I have no idea what the issue is really. According to @mrward it's not a good idea to run xattr.
Indeed, vsmac uses Mono's msbuild, so I guess the issue is there. @lewing @rainersigwald any hint as to where to start looking? (@lewing this is the same exact issue I asked for help the other day :D)
And yes, the xattr has nothing to do here, it's just because that project was downloaded through a browser, just creating a new project shows the same issue with msbuild:
$ dotnet new blazorwasm -o Wasm
$ cd Wasm
$ msbuild Wasm.csproj
....
_ResolveBlazorInputs:
Creating directory "obj/Debug/netstandard2.1/blazor/".
/Users/rodrigo/.nuget/packages/microsoft.aspnetcore.components.webassembly.build/3.2.0-preview3.20168.3/targets/Blazor.MonoRuntime.targets(348,5): error : Specified cast is not valid. [/private/tmp/BlazorWasm/BlazorWasm.csproj]
Done Building Project "/private/tmp/BlazorWasm/BlazorWasm.csproj" (default targets) -- FAILED.
@rodrmoya ah. My original assumption was that the quarantine attributes (which I know come from the downloading) would prevent certain required permissions. Turns out that was a red herring.
Instead, the issue seems to be, as @javiercn says, Mono's MSBuild — if I run your commands, clean again, then run dotnet build, the correct blazor.boot.json gets produced.
I have no idea what's up here. MSBuild should log much more information than that if a task throws an unhandled exception. And that task doesn't appear to do its own try/catch swallowing.
But I do repro the problem on a command line build with Mono 6.8.0.123.
With a hacked up MSBuild that annotates all errors with the stack that generated them I get:
at System.Threading.ThreadHelper.ThreadStart () [0x00000] in <f9d1b832704f410aa8ec771f4fe80552>:0 (348,5): error : Specified cast is not valid. at System.Environment.get_StackTrace () [0x00000] in <f9d1b832704f410aa8ec771f4fe80552>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
at System.Environment.get_StackTrace () [0x00000] in <f9d1b832704f410aa8ec771f4fe80552>:0
at Microsoft.Build.Framework.BuildErrorEventArgs..ctor (System.String subcategory, System.String code, System.String file, System.Int32 lineNumber, System.Int32 columnNumber, System.Int32 endLineNumber, System.Int32 endColumnNumber, System.String message, System.String helpKeyword, System.String senderName, System.DateTime eventTimestamp, System.Object[] messageArgs) [0x00000] in <640df2a8f71d4babbe2adee4d62ba891>:0
at Microsoft.Build.Utilities.TaskLoggingHelper.LogError (System.String subcategory, System.String errorCode, System.String helpKeyword, System.String file, System.Int32 lineNumber, System.Int32 columnNumber, System.Int32 endLineNumber, System.Int32 endColumnNumber, System.String message, System.Object[] messageArgs) [0x00000] in <06f3b14d9fc74afe97e8e1a587f3a030>:0
at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorFromException (System.Exception exception, System.Boolean showStackTrace, System.Boolean showDetail, System.String file) [0x00000] in <06f3b14d9fc74afe97e8e1a587f3a030>:0
at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorFromException (System.Exception exception, System.Boolean showStackTrace) [0x00000] in <06f3b14d9fc74afe97e8e1a587f3a030>:0
at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorFromException (System.Exception exception) [0x00000] in <06f3b14d9fc74afe97e8e1a587f3a030>:0
at Microsoft.AspNetCore.Components.WebAssembly.Build.GenerateBlazorBootJson.Execute () [0x00000] in <70cab4e2dc2b49b8889b1ce1760c4392>:0
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00000] in <7684aaa8e2ec4f8ba881e9f91c79f3cb>:0
And then I notice that this task isn't built from master but from here which does log an error
That overload of LogErrorFromException elides the stack trace. Hacking around that,
: error : Specified cast is not valid. [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.InternalSerialize (System.Reflection.MethodInfo methodInfo, System.Func`1[TResult] memberValue, System.Type memberType, System.Boolean writeXsiType) [0x0008d] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.WriteValue (System.Type memberType, System.Object memberValue) [0x00219] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.WriteMembers (System.Runtime.Serialization.ClassDataContract classContract, System.Runtime.Serialization.ExtensionDataObject extensionData, System.Runtime.Serialization.ClassDataContract derivedMostClassContract) [0x00130] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.WriteClass (System.Runtime.Serialization.ClassDataContract classContract) [0x00071] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterInterpreter.WriteToJson (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.Runtime.Serialization.ClassDataContract dataContract, System.Xml.XmlDictionaryString[] memberNames) [0x00054] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonFormatWriterGenerator+CriticalHelper+<>c__DisplayClass0_0.<GenerateClassWriter>b__0 (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.Runtime.Serialization.ClassDataContract dataContract, System.Xml.XmlDictionaryString[] memberNames) [0x0000b] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonClassDataContract.WriteJsonValueCore (System.Runtime.Serialization.XmlWriterDelegator jsonWriter, System.Object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle) [0x00027] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.JsonDataContract.WriteJsonValue (System.Runtime.Serialization.XmlWriterDelegator jsonWriter, System.Object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle) [0x00007] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteJsonValue (System.Runtime.Serialization.Json.JsonDataContract contract, System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle) [0x00000] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.RuntimeTypeHandle declaredTypeHandle) [0x00034] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.RuntimeTypeHandle declaredTypeHandle) [0x0003c] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObjectContent (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph) [0x0009a] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalWriteObject (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph) [0x00008] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.XmlObjectSerializer.InternalWriteObject (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.DataContractResolver dataContractResolver) [0x00000] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.DataContractResolver dataContractResolver) [0x00073] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph) [0x00000] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x0000d] in <2121a152126a43ffb19c36cfcc12a82a>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at Microsoft.AspNetCore.Components.WebAssembly.Build.GenerateBlazorBootJson.WriteBootJson (System.IO.Stream output, System.String entryAssemblyName) [0x00164] in <70cab4e2dc2b49b8889b1ce1760c4392>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
: error : at Microsoft.AspNetCore.Components.WebAssembly.Build.GenerateBlazorBootJson.Execute () [0x0001d] in <70cab4e2dc2b49b8889b1ce1760c4392>:0 [/Users/raines/Downloads/DOMException-EntryAlreadyExists/SwitchStream.Client/SwitchStream.Client.csproj]
I have no idea what's up here.
My guess would've been that it's trying to cast an empty (or null) object in order to serialize it into the resources field in the JSON, or one of its subfields.
What it winds up producing:
{
"cacheBootResources": true,
"config": [ ],
"debugBuild": true,
"entryAssembly": "SwitchStream.Client",
"linkerEnabled": false,
"resources": { }
}
What it should actually have looked like:
{
"cacheBootResources": true,
"config": [ ],
"debugBuild": true,
"entryAssembly": "Wasm",
"linkerEnabled": false,
"resources": {
"assembly": {
"Wasm.dll": "sha256-tquyNQz3Juz2yMoZxDdoI1e8f89wv2UF3cyVitStiIk=",
"(more items…)": {}
},
"pdb": {
"Wasm.pdb": "sha256-oObKG4w0H4wB4tBaOJjhDlxNGVQ36QP0vFb\/4kO8sQM="
},
"runtime": {
"dotnet.3.2.0-preview3.20168.1.js": "sha256-274clLanSGrn5tb3h9iFyKyVG0KYG2Um+VHF0kdNzHE=",
"dotnet.wasm": "sha256-JMG2FGgTy70oSWAVIpQcblmNZtV\/DaEaIZEaROjE7Eo="
}
}
}
(So resources winds up having none of the three properties assembly, pdb, runtime, and maybe the serializer is trying to access them.)
@pranavkm, can you take a gander at this? Repro project in OP and details on failure in https://github.com/dotnet/aspnetcore/issues/20259#issuecomment-607214332
@pranavkm any update?
@sayedihashimi I haven't looked as this as yet.
Speaking to @rodrmoya, VS4Mac uses mono as the runtime to invoke msbuild. Our task uses DataContractJsonSerializer to serialize JSON content and the error that @rainersigwald discovered here - https://github.com/dotnet/aspnetcore/issues/20259#issuecomment-607214332 - suggests that the error is thrown from Mono's implementation of the serializer.
@rodrmoya could you follow up with the Mono team to figure out how to address this?
This is being fixed as part of https://github.com/mono/mono/issues/19466
This is now fixed in vsmac with mono being bumped to the above mentioned fix, so will be available in the next 8.6 preview
Most helpful comment
This is now fixed in vsmac with mono being bumped to the above mentioned fix, so will be available in the next 8.6 preview