Closed
dotnet/corefx
#36906Description
From @tarekgh on June 14, 2017 15:54
@Spongman commented on Tue Jun 13 2017
a (.csproj) project a with an embedded text file, added using the VS2017.2 project properties UI.
on windows, it works fine.
on linux, it just shows:
$ dotnet --version
1.0.4
$ uname -a
Linux mybox 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2 (2017-04-30) x86_64 GNU/Linux
$ dotnet run
..\Resources\New Text Document.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
@danmosemsft commented on Tue Jun 13 2017
@tarekgh are there any known issues here?
@tarekgh commented on Wed Jun 14 2017
Please take a look at the issue https://github.com/dotnet/cli/issues/3695 this was CLI issue and I believe it is already fixed but I am not sure which release include the fix. I'll move this issue to CLI repo.
Copied from original issue: dotnet/cli#6866
Reacted by Francis Thérien, arthurvb, nzbart, James, Konstantin Petukhov, Jarno Rantala, Viktor Hofer, Joseph Musser, Dan Moseley, Adam Shakhabov and 12 more
Activity
nguerrera commentedon Jun 15, 2017
MSBuild does not support currently support non-string resources on .NET Core. However, it is not checking the resx data's type attribute, but instead blindly using the value as a string. This should either work or have a clear "not supported" error at build time.
Relevant snippet from repro project resx:
Code that is not checking the
typeattribute:https://github.com/Microsoft/msbuild/blob/cc727f715651f305639ad8635fefc40165299f86/src/Tasks/GenerateResource.cs#L2909-L2920
It might be easy enough to actually handle this ResxFileRef-to-string case correctly. If we do that, we still need a clear error in other non-string data cases.
eltiare commentedon Sep 3, 2017
I am eagerly awaiting the embedding of all resources via the commandline as it will make my life easier with the
watchcommand.ThatRendle commentedon Sep 4, 2017
As a stop-gap solution while we wait for resource embedding to become a properly-supported, cross-platform, I created a
dotnettool which does something vaguely similar: https://github.com/RendleLabs/Embedder/blob/master/README.md(I forgot to
git push, will do that soon)jetersen commentedon Nov 8, 2017
This also applies to images even on Windows using dotnet build, msbuild 😭
viktors-telle commentedon Dec 6, 2017
Any ETA on fixing this?
auxym commentedon Dec 11, 2017
I'm also getting with issue with
dotnet build/dotnet msbuild, but not with the msbuild.exe packaged with VS2017, which seems to correctly embed string resources.AlgorithmsAreCool commentedon Jan 17, 2018
This explains a lot. I had a WinForms application that would fail to launch at runtime with
dotnet buildbut worked fine in VS2017. I was getting an InvalidCastException when loading an image resource.EDIT
As auxym says,
dotnet msbuilddoes not work as of cli version 2.1.2. You need to call the msbuild visual studio installs. For me this is located at:For some reason this still does not work in release configuration. I have to use debug to get the resources embedded correctly. Hope this helps until a proper fix is available.
mikebridge commentedon Feb 1, 2018
I have a
ResourceManager.GetObjectcall on an embedded resource which succeeds on windows but fails with the following error on using dotnetcore 2.0.3 (from the dotnet-sdk-2.0.3 docker image) on Linux:Is this a related issue?
I have an embedded text file "grades.json" which is accessed via the autogenerated
Resources.Designer.csfile. That error message occurs here:danmoseley commentedon Feb 1, 2018
ResourceManager will support binary blobs in resources with https://github.com/dotnet/corefx/issues/26745. I am guessing this is also "Unable to cast object of type 'System.String' to type 'System.Byte[]'" .. @ViktorHofer can verify.
Bear in mind that Winforms is not supported on .NET Core so if it's actually a Winforms app you will hit more errors after this when you try to load a Winforms type.
One other Winforms caveat: the set of binary-serializable types is smaller in .NET Core than in .NET Framework (list) and it does not include for example Image, Icon and Font - types that the Winforms designer likes to binary serialize into resources.
mikebridge commentedon Feb 1, 2018
@danmosemsft this particular instance is a c# library called from a webapp.
danmoseley commentedon Feb 1, 2018
@mikebridge what are the
type/mimetypeyou see in the resx?eg
mikebridge commentedon Feb 1, 2018
@danmosemsft The resx file shows this:
I didn't realize it was specific to winforms---I can embed this file another way if necessary....
danmoseley commentedon Feb 1, 2018
Yeah,
ResxFileRefis a Winforms type for whatever reason (although presumably it doesn't need Winforms proper so it could be ported.) You'll want to embed as a string or a binary formatted string directly into the resx.87 remaining items
voltcode commentedon Jul 30, 2019
This fix should be backported to MSBuild 15 at least and .NET Core 2.1/2.2, resource files are a very old feature, lack of support for them prevents people on .NET FX from migrating onto .NET Core.
nguerrera commentedon Jul 30, 2019
@voltcode I'm afraid adding support for something that never worked in that combination would not be allowed for a servicing change. We keep a very high bar for that. Taking big features like this backwards adds too much risk. This was a very large change across three repositories. We have fixed this for .NET Core 3.0+ and MSBuild 16.3+, and that is all we can do without a time machine.
voltcode commentedon Jul 30, 2019
What do you mean it never worked? It worked in Visual Studio. This is a big inconsistency, resource files are from year 2003 and you're forcing people to move to VS 2019 (paid upgrade) to fix it.
Unless NET Core 3.0 will be supported in VS 2017?
nguerrera commentedon Jul 30, 2019
It is not supported in VS 2017. There has been a lot of work in msbuild, NuGet, the project system, and other VS components for .NET Core 3.
jnm2 commentedon Jul 30, 2019
@voltcode What I've been doing is using Visual Studio's .NET Framework msbuild which has always supported non-string resources rather than .NET Core's msbuild which had never supported them. I used this starting with VS2017:
nguerrera commentedon Jul 30, 2019
I mean .NET Core 2.x projects with .NET Core SDK 2.x behave as they always have. It is regrettable that they did not have the result of this work, but it is simply too late to change that.
.NET Core 2.x filled many gaps with .NET Framework vs. .NET Core 1.x, but not this one. We didn't backport all of those gap closings to 1.x either. We literally cannot do that. We have to defend every backport rigorously, and the change will be rejected if it is closing a gap that was always there.
We will get tenfold more passionate feedback when we break something in a servicing update. We are holding this bar with the best of intentions. The risk is simply too high.
voltcode commentedon Jul 30, 2019
thanks @jnm2 . Just to clarify by .NET FX you mean the real, old school MSBuild.exe, and by .NET Core msbuild you mean dotnet build command?
When writing build scripts, I would like exactly the same behavior between script and VS. To achieve this goal - what is better to use for scripts - MSBuild.exe or dotnet build ?
We hit the resources problem when using dotnet test in build scripts - as far as I understand - if we use MSBuild.exe to build entire solution and dotnet test with --no-build flag - we should be fine? We're using .NET Core 2.2.
rainersigwald commentedon Jul 30, 2019
Visual Studio uses MSBuild.exe to build. Using that will be closer to the VS build.
Yes, using MSBuild.exe followed by
dotnet test --no-buildsounds reasonable in your use case.voltcode commentedon Jul 31, 2019
Thanks @rainersigwald, we've tested your suggestion and it we're definitely going to stay on MSBuild.exe and avoid dotnet * tools as much as possible to replicate VS behavior.
jzabroski commentedon Nov 21, 2019
EDIT: *** IF YOU ARE RUNNING INTO THIS ERROR WHEN THEN READ THIS - YOUR BUILD SERVER'S "BUILD TOOLS FOR VISUAL STUDIO 2019" MAY NOT BE UP TO DATE ***
I am able to successfully run my app from my command line on my local dev machine, but cannot run it after it's being built in TeamCity.
Local Dev Machine
TeamCity Build Server
Visual Studio Build Tools 16.1.9

When I click "Launch", I get:
Attempt to fix
vs_buildtools__1704816089.1574373004.exe)7DA4388648C92544C97407C6F052FD6BC0317DB407CADAB9FDCB328A34D3E317Commit non-string resources instead of generating as part of build