PC Review


Reply
Thread Tools Rate Thread

Assembly.LoadFile and Code Analysis warning CA2001

 
 
Jesse Houwing
Guest
Posts: n/a
 
      31st Oct 2009
Hey all,

I've implemented a simple plug-in based file parser for a customer and
I'm running into CA2001, which I'd like to solve.

The problem is that I cannot find any information on how to solve this
error, other than removing my call to Assembly.LoadFile. There are some
alternatives, but they are either also in the blacklist for CA2001, or
they're deprecated.

What I'm trying to accomplish is to load my file format description
(classes decorated with custom attributes) from a specific directory
(e.g. /bin/formats).

I'm using the following code:

foreach (string dll in
Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),
"Formats"), "*.dll"))
{
Assembly ass = Assembly.LoadFile(dll);
Type[] types = ass.GetTypes();
}

Any other approaches I could use for this? Can I tell the framework to
load all my assemblies by adding a config directive? Or is there a Load*
method in Assembly that I might have missed?

--
Jesse Houwing
jesse.houwing at sogeti.nl
 
Reply With Quote
 
 
 
 
Jeroen Mostert
Guest
Posts: n/a
 
      31st Oct 2009
Jesse Houwing wrote:
> I've implemented a simple plug-in based file parser for a customer and
> I'm running into CA2001, which I'd like to solve.
>

It would have behooved you to spell out what CA2001 was. Would've saved me a
trip to Google.

For the rest of us, it's "Avoid calling problematic methods", blacklisting
several methods with problems, including Assembly.LoadFile().

> The problem is that I cannot find any information on how to solve this
> error, other than removing my call to Assembly.LoadFile.


Basically, it's because Microsoft wants you to use the GAC, or else muck
around with a new AppDomain. See
http://blogs.msdn.com/suzcook/archiv.../29/57143.aspx and
http://blogs.msdn.com/suzcook/archiv.../13/57180.aspx.

Personally, I'd just suppress the CA2001 warning. This is one area where
Microsoft's ideas of the perfect world just don't mesh with what people
actually want.

--
J.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly.LoadFile and Code Analysis warning CA2001 Jesse Houwing Microsoft Dot NET 0 30th Oct 2009 12:26 PM
Shared violation with Assembly.LoadFile =?Utf-8?B?QXNzZW1ibHkgZmlsZSBsb2NrZWQ=?= Microsoft Dot NET Compact Framework 1 20th May 2005 10:26 AM
Assembly.LoadFile question =?Utf-8?B?bXR2?= Microsoft Dot NET Framework 1 16th Dec 2004 10:42 AM
How to UNLOAD an Assembly after you LoadFile(...)?? mdb Microsoft Dot NET 2 2nd Sep 2004 08:54 PM
How to use Assembly.LoadFile to load assembly in different path? =?Utf-8?B?bGVlenE=?= Microsoft Dot NET Framework 0 19th Jun 2004 07:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:13 PM.