Conflict with Microsoft EventRegister Tool
See original GitHub issueI have a WebAPI project. I installed Microsoft EventRegister Tool (https://www.nuget.org/packages/Microsoft.Diagnostics.Tracing.EventRegister/1.1.11-beta) in it. I also installed Swashbuckle in the project. So far so good. But if I implemented a class which inherits from IOperationFilter in my project, I even can’t build my project successfully. I got the following error message:
Error 1 Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
And in the Output panel of VS, I can see this error:
1>EXEC : error : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 1> LoaderException: 1> System.TypeLoadException: Method ‘Apply’ in type ‘EventRegisterTestingSwashbuckle.ComplexTypeQueryParamFilter’ from assembly ‘EventRegisterTestingSwashbuckle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ does not have an implementation.
Here is my code of the filter:
public class ComplexTypeQueryParamFilter : IOperationFilter
{
public void Apply(Operation operation, DataTypeRegistry dataTypeRegistry, ApiDescription apiDescription)
{
}
}
I found that EventRegister add the following sentence in my project file:
<Import Project="..\packages\Microsoft.Diagnostics.Tracing.EventRegister.1.1.11-beta\build\Microsoft.Diagnostics.Tracing.EventRegister.targets" Condition="Exists('..\packages\Microsoft.Diagnostics.Tracing.EventRegister.1.1.11-beta\build\Microsoft.Diagnostics.Tracing.EventRegister.targets')" />If I remove it, then I can build the project successfully and seems everything goes well. I have no idea why this happens. Do you have any thoughts on this?
Thanks, Peter
Issue Analytics
- State:
- Created 9 years ago
- Comments:5
I sent an email to the owner of EventRegister and got the answer from him. I paste his reply below:
_EventRegister as part of its build rules uses reflection on the built assembly to look for EventSources so that it can do validation on them. If you are not using the windows Event log as a target of your event source you do not strictly need this build time process (it just detects problems with your EventSource sooner).
As part of that reflection use, it tries to load the build assembly, and that is where the error is happening. Swashbuckle is likely doing ‘tricky’ things that make loading problematic.
One simple work-around is to simply turn off the build time rules (which is what you have done below). A cleaner way of accomplishing the same thing is to only use the EventSource.Redist Nuget package (which does not even include EventRegister) instead of the full EventSource package in your application.
Event simpler, is that if you can use the version built into the .NET Runtime (since V4.5), then this too will avoid the problem.
This issue (that in general the ability to load an assembly for inspection may be problematic), is a known issue. We know how to solve it in the long term, but in the short term you need work around it._
Thanks for replying Peter