https://github.com/sschmid/roslynunittestissue
Using Roslyn to get class attributes works in console app but fails in unit test
https://github.com/sschmid/roslynunittestissue
Last synced: over 1 year ago
JSON representation
Using Roslyn to get class attributes works in console app but fails in unit test
- Host: GitHub
- URL: https://github.com/sschmid/roslynunittestissue
- Owner: sschmid
- Created: 2022-12-12T15:52:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-13T09:51:24.000Z (over 3 years ago)
- Last Synced: 2025-02-13T20:44:19.318Z (over 1 year ago)
- Language: C#
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Roslyn Unit Test Issue
## Setup
- One classlib project `MyClasslib` which contains one class [MyClass.cs](https://github.com/sschmid/RoslynUnitTestIssue/blob/main/MyClasslib/MyClass.cs), which has an attribute `[Obsolete("My Reason")]`
- One console project `MyConsoleApp` which contains [Helper.cs](https://github.com/sschmid/RoslynUnitTestIssue/blob/main/MyConsoleApp/Helper.cs) which uses Roslyn to get the attributes from [MyClass.cs](https://github.com/sschmid/RoslynUnitTestIssue/blob/main/MyClasslib/MyClass.cs)
- One unit test project `Tests` which also uses [Helper.cs](https://github.com/sschmid/RoslynUnitTestIssue/blob/main/MyConsoleApp/Helper.cs), but prints a different result which is unexpected!
## Issue
Using Roslyn to get the attributes of [MyClass.cs](https://github.com/sschmid/RoslynUnitTestIssue/blob/main/MyClasslib/MyClass.cs) works as expected, but the same code fails whe running it in a unit test.
### Expected output:
`System.ObsoleteAttribute("My Reason")`
### Unit test output:
`Obsolete`
Why? Please help!
See https://github.com/sschmid/RoslynUnitTestIssue/issues/1