Created
January 26, 2016 23:08
-
-
Save Vannevelj/a751ff4c8c22a1a61c3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) | |
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) | |
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() | |
at System.Threading.ThreadHelper.ThreadStart_Context(Object state) | |
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) | |
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) | |
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) | |
at System.Threading.ThreadHelper.ThreadStart() | |
InnerException: | |
HResult=-2147467261 | |
Message=Object reference not set to an instance of an object. | |
Source=Microsoft.CodeAnalysis.Workspaces | |
StackTrace: | |
at Microsoft.CodeAnalysis.Rename.RenameLocations.ReferenceProcessing.<GetRenamableDefinitionLocationsAsync>d__6.MoveNext() | |
--- End of stack trace from previous location where exception was thrown --- | |
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) | |
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) | |
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() | |
at Microsoft.CodeAnalysis.Rename.RenameLocations.<AddLocationsReferenceSymbolsAsync>d__28.MoveNext() | |
--- End of stack trace from previous location where exception was thrown --- | |
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) | |
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) | |
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() | |
at Microsoft.CodeAnalysis.Rename.RenameLocations.<FindAsync>d__24.MoveNext() | |
--- End of stack trace from previous location where exception was thrown --- | |
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) | |
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) | |
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() | |
at Microsoft.CodeAnalysis.Rename.Renamer.<RenameSymbolAsync>d__3.MoveNext() | |
InnerException: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?symbol | |
Local System.Int32[missing] o | |
CanBeReferencedByName: true | |
CanBeReferencedByNameIgnoringIllegalCharacters: true | |
CanScheduleToStack: true | |
ConstantValue: null | |
ContainingAssembly: Assembly projName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null | |
ContainingModule: NetModule projName.exe | |
ContainingNamespace: Namespace ConsoleApplication1 | |
ContainingSymbol: Method void ConsoleApplication1.MyClass.Method() | |
ContainingType: NamedType ConsoleApplication1.MyClass | |
Dangerous_IsFromSomeCompilation: true | |
DeclarationKind: RegularVariable | |
DeclaredAccessibility: NotApplicable | |
DeclaringCompilation: {Microsoft.CodeAnalysis.CSharp.CSharpCompilation} | |
DeclaringSyntaxReferences: Length = 1 | |
HasConstantValue: false | |
HasUnsupportedMetadata: false | |
HasUseSiteError: false | |
HighestPriorityUseSiteError: 2147483647 | |
IdentifierToken: SyntaxToken IdentifierToken o | |
IsAbstract: false | |
IsCatch: false | |
IsCompilerGenerated: false | |
IsConst: false | |
IsDefinition: true | |
IsExtern: false | |
IsFixed: false | |
IsFor: false | |
IsForEach: false | |
IsImplicitlyDeclared: false | |
IsImportedFromMetadata: false | |
IsOverride: false | |
IsPinned: false | |
IsSealed: false | |
IsStatic: false | |
IsUsing: false | |
IsVar: false | |
IsVirtual: false | |
IsWritable: true | |
Kind: Local | |
Language: "C#" | |
Locations: Length = 1 | |
MetadataName: "o" | |
Microsoft.CodeAnalysis.ILocalSymbol.IsFunctionValue: false | |
Microsoft.CodeAnalysis.ILocalSymbol.Type: ErrorType System.Int32[missing] | |
Microsoft.CodeAnalysis.ILocalSymbolInternal.IsImportedFromMetadata: false | |
Microsoft.CodeAnalysis.ILocalSymbolInternal.SynthesizedKind: UserDefined | |
Microsoft.CodeAnalysis.ISymbol.ContainingAssembly: Assembly projName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null | |
Microsoft.CodeAnalysis.ISymbol.ContainingModule: NetModule projName.exe | |
Microsoft.CodeAnalysis.ISymbol.ContainingNamespace: Namespace ConsoleApplication1 | |
Microsoft.CodeAnalysis.ISymbol.ContainingSymbol: Method void ConsoleApplication1.MyClass.Method() | |
Microsoft.CodeAnalysis.ISymbol.ContainingType: NamedType ConsoleApplication1.MyClass | |
Microsoft.CodeAnalysis.ISymbol.DeclaredAccessibility: NotApplicable | |
Microsoft.CodeAnalysis.ISymbol.DeclaringSyntaxReferences: Length = 1 | |
Microsoft.CodeAnalysis.ISymbol.IsAbstract: false | |
Microsoft.CodeAnalysis.ISymbol.IsDefinition: true | |
Microsoft.CodeAnalysis.ISymbol.IsImplicitlyDeclared: false | |
Microsoft.CodeAnalysis.ISymbol.IsOverride: false | |
Microsoft.CodeAnalysis.ISymbol.IsSealed: false | |
Microsoft.CodeAnalysis.ISymbol.IsStatic: false | |
Microsoft.CodeAnalysis.ISymbol.IsVirtual: false | |
Microsoft.CodeAnalysis.ISymbol.Kind: Local | |
Microsoft.CodeAnalysis.ISymbol.Locations: Length = 1 | |
Microsoft.CodeAnalysis.ISymbol.Name: "o" | |
Microsoft.CodeAnalysis.ISymbol.OriginalDefinition: Local System.Int32[missing] o | |
Name: "o" | |
ObsoleteAttributeData: null | |
ObsoleteState: False | |
OriginalDefinition: Local System.Int32[missing] o | |
OriginalSymbolDefinition: Local System.Int32[missing] o | |
RefKind: None | |
RequiresCompletion: false | |
SynthesizedKind: UserDefined | |
Type: ErrorType System.Int32[missing] | |
_constantTuple: null | |
_containingSymbol: Method void ConsoleApplication1.MyClass.Method() | |
_declarationKind: RegularVariable | |
_identifierToken: SyntaxToken IdentifierToken o | |
_initializer: EqualsValueClauseSyntax EqualsValueClause = 5 | |
_isSpecificallyNotPinned: 0 | |
_locations: Length = 1 | |
_type: ErrorType System.Int32[missing] | |
_typeSyntax: PredefinedTypeSyntax PredefinedType int | |
binder: {Microsoft.CodeAnalysis.CSharp.BlockBinder} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static void Execute() | |
{ | |
var source = @" | |
using System; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class MyClass | |
{ | |
private int oAsInt32; | |
void Method() | |
{ | |
int o = 5; | |
Console.WriteLine(oAsInt32); | |
} | |
} | |
}"; | |
var workspace = new AdhocWorkspace(); | |
var projectId = ProjectId.CreateNewId(); | |
var project = workspace.AddProject(ProjectInfo.Create(projectId, VersionStamp.Create(), "NewProject", "projName", LanguageNames.CSharp)); | |
var document = workspace.AddDocument(project.Id, "NewFile.cs", SourceText.From(source)); | |
var root = document.GetSyntaxRootAsync().Result; | |
var editor = DocumentEditor.CreateAsync(document).Result; | |
var semanticModel = document.GetSemanticModelAsync().Result; | |
var localIdentifier = root.DescendantNodes().OfType<VariableDeclaratorSyntax>().Skip(1).First(); | |
var symbol = semanticModel.GetDeclaredSymbol(localIdentifier); | |
var renamedSolution = Renamer.RenameSymbolAsync(project.Solution, symbol, "oAsInt32", null).Result; | |
Console.WriteLine(renamedSolution.GetProject(projectId).GetDocument(document.Id).GetTextAsync().Result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment