Skip to content

Instantly share code, notes, and snippets.

class MyClass
{
private int oAsInt32;
void Method(object o)
{
var oAsInt32 = o as int?;
if (oAsInt32 != null)
{
Console.Write(oAsInt32.Value);
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at ConsoleApplication1.Test.Execute() in D:\Github\Thesis\SourceCode\ThesisConsole\ConsoleApplication1\Test.cs:line 47
at ConsoleApplication1.Program.Main(String[] args) in D:\Github\Thesis\SourceCode\ThesisConsole\ConsoleApplication1\Program.cs:line 18
Test method VSDiagnostics.Test.Tests.General.TryCastUsingAsNotNullInsteadOfIsAsTests.TryCastWithoutUsingAsNotNull_BranchedIfStatement threw exception:
RoslynTester.Helpers.Testing.AssertionException:
Expected document is not the same as the resulting one.
Expected:
using System;
using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Text;
namespace ConsoleApplication1
{
internal class Test
Test method VSDiagnostics.Test.Tests.General.TryCastUsingAsNotNullInsteadOfIsAsTests.TryCastWithoutUsingAsNotNull_ConflictingLocalExplicitlyReferringToField threw exception:
System.AggregateException: One or more errors occurred. ---> System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.VariableDeclaratorSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax'.
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement(TNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList(SyntaxList`1 list)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitBlock(BlockSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.Accept(CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitIfStatement(If
void Method(object o)
{
if (o is string && ((string) o).Length > 1)
{
}
}
> VSDiagnostics.dll!VSDiagnostics.Diagnostics.General.TryCastWithoutUsingAsNotNull.TryCastWithoutUsingAsNotNullCodeFix.GetNewIdentifier(string currentIdentifier, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type, Microsoft.CodeAnalysis.SemanticModel semanticModel) Line 156 C#
VSDiagnostics.dll!VSDiagnostics.Diagnostics.General.TryCastWithoutUsingAsNotNull.TryCastWithoutUsingAsNotNullCodeFix.UseAsAsync(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.SyntaxNode statement) Line 110 C#
VSDiagnostics.dll!VSDiagnostics.Diagnostics.General.TryCastWithoutUsingAsNotNull.TryCastWithoutUsingAsNotNullCodeFix.RegisterCodeFixesAsync.AnonymousMethod__0(System.Threading.CancellationToken x) Line 33 C#
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.CodeActions.CodeAction.DocumentChangeAction.GetChangedDocumentAsync(System.Threading.CancellationToken cancellationToken) Unknown
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(Sy
at VSDiagnostics.Diagnostics.General.TryCastWithoutUsingAsNotNull.TryCastWithoutUsingAsNotNullCodeFix.GetNewIdentifier(String currentIdentifier, TypeSyntax type, SemanticModel semanticModel) in
D:\Github\VSDiagnostics\VSDiagnostics\VSDiagnostics\VSDiagnostics\Diagnostics\General\TryCastWithoutUsingAsNotNull\TryCastWithoutUsingAsNotNullCodeFix.cs:line 156
?semanticModel.GetTypeInfo(type)
'semanticModel.GetTypeInfo(type)' threw an exception of type 'System.NullReferenceException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467261
HelpLink: null
IPForWatsonBuckets: {0}
InnerException: null
IsTransient: false
Message: "Object reference not set to an instance of an object."
RemoteStackTrace: null
<entry>
<record>576</record>
<time>2016/01/23 00:54:09.530</time>
<type>Error</type>
<source>TryCastWithoutUsingAsNotNullCodeFix</source>
<description>One or more errors occurred.&#x000D;&#x000A; at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)&#x000D;&#x000A; at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)&#x000D;&#x000A; at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.&lt;&gt;c__DisplayClass13_0.&lt;InvokeCore&gt;b__0()&#x000D;&#x000A; at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformAction(IExtensionManager extensionManager, Object extension, Action action)</description>
</entry>