Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve CA 1009 warning in Visual Studio

I have some C# code that loads an assembly from a certain path like so:

assembly = System.Reflection.Assembly.LoadFrom(assemblyPath);

When I compile, Visual Studio Code Analysis throws this warning:

warning : CA2001 : Microsoft.Reliability : Remove the call to Assembly.LoadFrom ...

I'm looking for a way to resolve this warning (without suppressing it). Is there an alternative to LoadFrom that'll do that for me (I know LoadFile isn't it)?

like image 595
Frederick The Fool Avatar asked Dec 05 '25 20:12

Frederick The Fool


1 Answers

If your code works and does what you expect, then overrule the warning. The warning is there to bring your attention to things that might have edge-cases. If you have read what it says about CA 1009, and you understand the caveats, then: move on.

For loading from a specific path, LoadFrom may be the correct call. The only ways to totally remove that would be to:

  • remove the requirement to load from a specific path
  • use a custom AppDomain with different probing-paths, and use MarshalByRefObject to chat between them
like image 139
Marc Gravell Avatar answered Dec 08 '25 10:12

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!