Message 1 of 6
Unit test common runtime language detected invalid program when calling method.GetCustomAttributes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to define a unit test, Using Xunit and FluentAssertions.
In this test i want to list all command names from the methods in our code for example
[CommandMethod("SOME-COMMAND")]
public void SomeCommand()
{
// some method
}
[CommandMethod("SOME-COMMAND-1")]
public void SomeCommandOne()
{
// some method
}
I want result the names of the command like
SOME-COMMAND
SOME-COMMAND-1
This list will i use to compare all the commands in our UI with our Code.
I started with the following code
var assembly = Assembly.GetAssembly(typeof(EditorCommands));
var allTypes = AllTypes.From(assembly); // FluentAssertions.Types
var allMethods = allTypes.SelectMany(x => x.GetMethods()).ToArray();
foreach (var method in allMethods)
{
var attributes = method.GetCustomAttributes(typeof(CommandMethodAttribute), false);
foreach (var attribute in attributes)
{
var commandAttribute = attribute as CommandMethodAttribute;
var commandName = commandAttribute.GlobalName;
}
}
At line 11 in the sample code above i geth the following Exception
System.InvalidProgramException: 'Common Language Runtime detected an invalid program.'
Somehow it seems accoremgd.dll is protected as AutoCAD is not running, how can I get this working without running AutoCAD.