New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCastException when icon is set in autogenerated form designer code #163

tewarid opened this Issue Dec 5, 2018 · 3 comments


None yet
3 participants

tewarid commented Dec 5, 2018

  • .NET Core Version: 3.0 Preview1
  • Have you experienced this same bug with .NET Framework?: No

Problem description:

Crash at runtime where icon is set as follows in autogenerated form designer code

            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

Actual behavior:

Following exception is thrown when running using dotnet CLI or vscode

Exception has occurred: CLR/System.InvalidCastException
An unhandled exception of type 'System.InvalidCastException' occurred in...

Expected behavior:

No crash, form icon is set. Crash does not happen and icon is set when debugging via Visual Studio 2019 preview.

Minimal repro:


This comment has been minimized.

wjk commented Dec 5, 2018

This problem you're seeing is caused by Microsoft/msbuild#2221. The reason it works when building in VS is because VS uses .NET Framework MSBuild, which does not suffer from the above issue, which is specific to .NET Core MSBuild. I opened Microsoft/msbuild#3819 to try to fix this, but it hasn't been reviewed since I fixed the remaining test failures three weeks ago. Until we get that PR merged (and the version of .NET Core MSBuild you're using is updated to include the fix) there's not much you can do about this other than build using VS. Sorry about this!


This comment has been minimized.


merriemcgaw commented Dec 5, 2018

Duplicate of Microsoft/msbuild#2221

@merriemcgaw merriemcgaw marked this as a duplicate of Microsoft/msbuild#2221 Dec 5, 2018

@merriemcgaw merriemcgaw closed this Dec 5, 2018


This comment has been minimized.


merriemcgaw commented Dec 5, 2018

Thank you to @wjk for spotting this dupe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment