Hi, I'm creating a build definition on VSTS, for some tests I'm adding files inside a resx file, works on my machine but in VSTS I'm getting this error:
2017-09-01T20:07:32.3731498Z [command]d:a_tool\dncs\2.0.0\x64\dotnet.exe test d:a\1\s\src\Tests\Ommited.UnitTests.csproj --logger trx;logfilename=TEST.xml
2017-09-01T20:07:34.3419920Z Build started, please wait...
2017-09-01T20:07:39.7888511Z Build completed.
2017-09-01T20:07:39.7888511Z
2017-09-01T20:07:39.7898460Z Test run for d:a\1\s\src\Tests\Ommited\bin\Debug\netcoreapp2.0\Ommited.dll(.NETCoreApp,Version=v2.0)
2017-09-01T20:07:39.8286362Z Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
2017-09-01T20:07:41.9520461Z Failed OmmitedTest
2017-09-01T20:07:41.9520461Z Error Message:
2017-09-01T20:07:41.9560273Z Initialization method Ommited.TestInitialize threw exception. System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Byte[]'..
2017-09-01T20:07:41.9600087Z Stack Trace:
2017-09-01T20:07:41.9649846Z at Ommited.ExtensionsResources.get_TestFile() in d:a\1\s\src\Tests\Ommited\Resources\ExtensionsResources.Designer.cs:line 564
2017-09-01T20:07:41.9689653Z at Ommited.TestInitialize() in d:a\1\s\src\Tests\Ommited.cs:line 52
I added the Task .NET Core Tool Installer to make sure the SDK 2.0.0 was being used but I'm getting the same error.
Its there a way to workaround this?
Thanks
Hi! Did you find a solution? I just found the same problem
@MeliSantana nop, not yet
@smadala can you please look into this?
@MeliSantana @JuanZamudioGBM Can you share repro project?
@smadala Here you go, this fails in vsts when I build and then run the tests (both Tasks are .NET Core (Preview) 2)
TaskRepro.zip
@JuanZamudioGBM Thanks for repro.
I was able to repro the issue local dev machine.
There was difference between "Visual Stusio build" and "dotnet build"(which is used by "dotnet test" ).
If I run tests(dotnet test --no-build) after building with VS, test works fine.
VS Msbuild.exe file version: 15.3.409.57025
dotnet sdk Microsoft.Build.dll file version: 15.3.246.41955
/cc @nigurr @eerhardt Do you aware any changes which can cause this behavior changes in MSbuild?
It looks like the test is using a resource that looks like:
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TestFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\TestFile.svg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
This uses System.Windows.Forms, which is not a supported on .NET Core. When building using dotnet build|run|test, MSBuild is running on .NET Core and can only load assemblies that work properly on .NET Core. When building in VS or using msbuild.exe on Windows, MSBuild is running on the full .NET Framework, which can load System.Windows.Forms.
At the very least, I think dotnet build on .NET Core should raise an error that it can't support this type of .resx file. At the best, it would be great if dotnet build supported this type of .resx file.
This problem is not specific to test, but it would happen for any app built using dotnet build. I'll move this issue to the dotnet/sdk repo.
@eerhardt do you know how do I avoid this? This is a new project started from scratch in VS2017 and .net core 2, I created the Resx file from within VS2017.
Checking my resource files all have this (even the ones with only strings)
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
Thanks a lot for looking into this
I've opened https://github.com/dotnet/sdk/issues/1568 for this issue. This issue can be closed as a dupe.
@JuanZamudioGBM - I'm not exactly sure what those reader and writer nodes are actually used for. But I think you can ignore them.
I know we've tested pure string resources. Here is an example in our tests:
https://github.com/dotnet/sdk/blob/master/TestAssets/TestProjects/KitchenSink/TestLibrary/Resources.resx#L120-L122
https://github.com/dotnet/sdk/blob/master/TestAssets/TestProjects/KitchenSink/TestLibrary/Resources.fr.resx#L120-L122
I'm not sure how to embed a file in a .resx with .NET Core's command line dotnet build. One different option would be to embed the .svg file directly using an <EmbeddedResource> item in your .csproj.
<EmbeddedResource Include="TestFile.svg" />
You won't be able to use the generated TestResources.Designer.cs code to access the resource. Instead, you can use the ResourceManager class yourself to load the resource.
@eerhardt Thanks, that worked
Most helpful comment
Hi! Did you find a solution? I just found the same problem