Bug Report T655314
Visible to All Users

DeclareProvider creates duplicated code and then crashes

created 7 years ago

It seems that "Declare Class" has some issues with .NET Standard projects (perhaps even .NET Core; but I haven't seen it do that on .NET Framework projects yet):

C#
System.AggregateException : One or more errors occurred. ---> Object reference not set to an instance of an object. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.InvokeWorker(Func`1 getFromDocument,IProgressTracker progressTracker,CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.<>c__DisplayClass18_0.<InvokeCore>b__0() at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformAction(IExtensionManager extensionManager,Object extension,Action action) ---> (Inner Exception #0) System.NullReferenceException : Object reference not set to an instance of an object. at DevExpress.CodeAnalysis.Refactorings.Actions.AddDocumentOperation.Apply(Workspace workspace,CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CodeActions.CodeActionOperation.TryApply(Workspace workspace,IProgressTracker progressTracker,CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService.ProcessOperations(Workspace workspace,ImmutableArray`1 operations,IProgressTracker progressTracker,CancellationToken cancellationToken) at async Microsoft.CodeAnalysis.Editor.Implementation.CodeActions.CodeActionEditHandlerService.ApplyAsync(<Unknown Parameters>)<---

To trigger this, simply open a .NET Standard project (or create a new one), then type code as follows (in case it matters: targetting .NET Standard 1.3, no multi-target):

C#
var test = new TestClass();

Afterwards place the Cursor on "TestClass" and invoke "Declare" > "Declare Class" (make sure to not leave the cursor at the end of the line, which only shows the Visual Studio "Generate class 'TestClass' in new file" etc. refactorings).

As result, the provider crashes with the yellow bar on top that says "'DeclareProvider' encountered an error and has been disabled".
This also created two files: TestClass.cs and TestClass1.cs. The former has a complete and useful declaration of the class (as expected), but the latter has an unformatted string of text that lacks any kind of whitespace and doesn't even compile:

C#
namespaceNetStandardLib{publicclassTestClass{publicTestClass(){}}}

This is on latest Visual Studio 2017 Community Edition (15.7.5).

Comments (1)
DevExpress Support Team 7 years ago

    Hello,
    We have reproduced this issue. Please give us some time to fix it. You will be automatically notified once we do this.

    Answers approved by DevExpress Support

    created 7 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.