NullReferenceException in out-of-process designer if resource contains data of type System.Resources.ResXNullRef
Environment
Microsoft Visual Studio Professional 2022 Version 17.13.6 VisualStudio.17.Release/17.13.6+35931.197 Microsoft .NET Framework Version 4.8.09032
.NET version
.NET 9.0
Did this work in a previous version of Visual Studio and/or previous .NET release?
No response
Issue description
If a resource file within a project contains data of type System.Resources.ResXNullRef the desginer just shows this message:
Steps to reproduce
Open and build the sample project, then open Form1.
Diagnostics
[15:01:38.274771] fail: StreamJsonRpc.RemoteInvocationException: Object reference not set to an instance of an object.
at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.Host.ServerHost.<InitializeAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.DotNet.DesignTools.Client.DesignToolsClientLoader.<CreateClientAsync>d__29.MoveNext()
RPC server exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.CodeDomBuilder.StronglyTypedResourceBuilder.Create(Dictionary`2 resourceList, String baseName, String generatedCodeNamespace, String resourcesNamespace, CodeDomProvider codeProvider, Boolean internalClass, String[]& unmatchable)
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.CodeDomBuilder.StronglyTypedResourceBuilder.Create(Dictionary`2 resourceList, String baseName, String generatedCodeNamespace, CodeDomProvider codeProvider, Boolean internalClass, String[]& unmatchable)
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.ResXGlobalObject.BuildType()
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.ResXGlobalObject.GetObjectType()
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.GlobalObject.get_ObjectType()
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.ResXGlobalObject.get_Children()
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.ProjectResXGlobalObjectProvider.AddResourcesToGlobalCollection(String identifier, GlobalResourceFileData globalResource)
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.ProjectResXGlobalObjectProvider.UpdateGlobalObjectCollectionStoreForSource(String identifier)
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.GlobalObjectProvider.InitializeOrUpdateProjectResources(GlobalResourceFileData[] resources)
at Microsoft.DotNet.DesignTools.Server.GlobalObjects.GlobalObjectService.InitializeOrUpdateGlobalResources(GlobalResourceFileData[] globalResources)
at Microsoft.DotNet.DesignTools.Server.DesignToolsServer.InitializeAsync(ServerInitializationOptions options)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
I saw the discussion, but I don't see were it says its unsupported, I just see a pull request with a fix regarding ResXNullRef: https://github.com/dotnet/msbuild/pull/4637
Also, while your workaround makes the designer work, the value is not "null" but "string.Empty" so thats not the same.
Sorry for the wrong interpretation. ResXNullRef just removes the Serializable attribute https://github.com/dotnet/winforms/pull/1425
You can try to use local resources, add System.Resources.ResXNullRef in Form1.resx as a workaround.
Thanks for the workaround. ~~While this works with the sample project it does not with our production project. This uses DevExpress controls with localization and crashes while setting ButtonEdit.Properties.ImageOptions.SvgImage to ResXNullRef in a local form resource with the exact same stack trace. This project does not have a single ResXNullRef in a global resources. Unfortunately I'm not able to reproduce this in a plain WinForms project.~~
Edit: I've found the cause for the problems with our project setup. I can confirm now, that the problem is only related to global resources.
@JeremyKuhne, is this something you would take a quick look at?
@JeremyKuhne, is this something you would take a quick look at?
@KlausLoeffelmann Unfortunately, not at the moment. If you or @Shyam-Gupta are able to do a quick look and need my input, please ping me.
The new "Resource Explorer" adds this type (System.Resources.ResXNullRef, System.Windows.Forms ) for each localized resource when the text of the neutral language is used. For now, our workaround is to use the "Managed Resources Editor (Legacy)" in VS 2022.
However, in VS 2026, this legacy editor will be removed, so this workaround will no longer work!