dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.38k stars 971 forks source link

System.Resources.MissingManifestResourceException occurs on restore resources from .resx #638

Closed mikhailovalex closed 5 years ago

mikhailovalex commented 5 years ago

It is impossible to read an object from resources when the form or user control has a non default namespace

Actual behavior: System.Resources.MissingManifestResourceException: 'Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "DifferentNamespace.Form1.resources" was correctly embedded or linked into assembly "NetCore_Resources" at compile time, or that all the satellite assemblies required are loadable and fully signed.'

Expected behavior: NetCore project should read an object from resources

Minimal repro: Run the attached example - NetCore_Resources.NetCore.sln NetCore_Resources.zip

Lohnegrim commented 5 years ago

Hi, I encountered the same problem with my .Core 3 tests, this doesn't only happen, when there is a Namespace, it also happens, when the Classname of the Form is different from the Filename. In Order to workaround this issue, you currently have to add the following to your NetCore_Resources.NetCore.csproj file: `

Form1.cs

`

merriemcgaw commented 5 years ago

@dreddy-work can you take a look at this as part of the larger RESX work?

dreddy-work commented 5 years ago

@mikhailovalex do you see a different behavior on .NET 4.7 for this scenario?

mikhailovalex commented 5 years ago

@dreddy-work Sure. You can open a project in an attached example NetCore_Resources.sln. It's built and starts without any exception. Otherwise "NetCore_Resources.NetCore.sln" solution shows me this exception : image

199621616 commented 5 years ago

Original message translated to English I'm having the same problem. Copy the. Net4.6.1 fully functional project containing files to the WinForm project in. NetCore, the compilation passes normally, but there are exceptions to the run: Void HandleResourceStreamMissing (System.String) ^Message:Could not find any, appropriate for the specified Culture or the neutral culture. Make sure "Medicare interface Workstation Xinjiang. Form Medicare Interface Workstation Xinjiang. Resources "is correctly embedded or linked into assembly " Medicare interface workstation _ Xinjiang "at compile Satellite assemblies required is loadable and fully signed.^source:system.private.corelib^stacktrace:at/System.resour Ces. ManifestBasedResourceGroveler.HandleResourceStreamMissing (String fileName)


我遇到了同样的问题。 将.Net4.6.1完全正常运行的项目包含文件复制到.NetCore的WinForm项目中,编译正常通过,但是运行有异常: Void HandleResourceStreamMissing(System.String)^Message:Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "医保接口工作站_新疆.Form医保接口工作站_新疆.resources" was correctly embedded or linked into assembly "医保接口工作站_新疆" at compile time, or that all the satellite assemblies required are loadable and fully signed.^Source:System.Private.CoreLib^StackTrace: at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)

199621616 commented 5 years ago

Original Message Translated to English

This is the biggest hurdle we encounter in migrating desktop programs. It seems that it is related to the resource files in previous versions of Core3 that only support characters and do not support binary resources. Hope to resolve as soon as possible, it blocks us from migrating desktop programs to Core3.


这是我们迁移桌面程序中遇到的最大障碍。 似乎它与Core3以前版本中资源文件只支持字符、不支持二进制资源有关。希望尽快解决,它阻断了我们向Core3迁移桌面程序。

merriemcgaw commented 5 years ago

@Olina-Zhang can you check this scenario now?

199621616 commented 5 years ago

Edited to add English translation (in future please do this with your comments) 3.0.0-Prevew7 doesn't solve this problem yet? Hope to solve in 3.0.0-Prevew7, do not modify to 3.0.0-Prevew8

3.0.0-Prevew7还不能解决这个问题嘛?希望在3.0.0-Prevew7中能解决,不要再改性到3.0.0-Prevew8

RussKie commented 5 years ago

Please write your comments in English

dreddy-work commented 5 years ago

@rainersigwald , I am thinking this is one of the scenario that might have been solved by your changes in msbuild. Can you help me point to the build that i can verify against?

dreddy-work commented 5 years ago

@ericstj and @rainersigwald , it seems msbuild is embedding resources under project name instead of Namespace name. Thus, resource manager failing to find. This was working when applications continue with default namespace but throw an exception when they do not opt into default name space. Following are the embedded resources from Net core and classic framework applications with exact same source code.

image

ericstj commented 5 years ago

@nguerrera @dsplaisted

nguerrera commented 5 years ago

I believe this will be the issue of DependentUpon not being set and is a duplicate. Will follow up with further details.

nguerrera commented 5 years ago

We had talked about having some way to tell msbuild to fall back to a file naming convention when there is no DependentUpon. @davkean I think you were going to propose something? Is there an msbuild issue yet?

nguerrera commented 5 years ago

https://github.com/dotnet/winforms/issues/638#issuecomment-477053971 is indeed the workaround.

Without DependentUpon msbuild can’t figure out the namespace and class used in the source file and will use the resx file name and RootNamespace (which is defaulted to the project name).

If we add support for convention, we need to put it behind a flag or we will break existing projects. We can then opt in to the flag by default for netcoreapp3.

If there isn’t already an msbuild issue, I will move this one

dreddy-work commented 5 years ago

I am not sure if there is already an issue in msbuild repo. Feel free to move this.

nguerrera commented 5 years ago

I was asking @davkean if there was an issue because I think he was going to file a proposal.

davkean commented 5 years ago

There's an issue here, https://github.com/dotnet/project-system/issues/4807, but I've run out of time to figure out/file a proposal. If MSBuild/SDK could pick this up, that would be great.

dreddy-work commented 5 years ago

Now that we are tracking the issue in msbuild repo, closing this issue here.