2
votes

I think i have used a quite common pattern:

var result = from a in AppDomain.CurrentDomain.GetAssemblies()
                         from t in a.GetTypes()
                         where t.IsDefined(typeof(TAttribute), inherit)
                         select t;

If i call the code from Program.cs it works.

Also if i call it from a form it works - sometimes, depending on the form. Sometimes it is only throwing an error: Mindestens ein Typ in der Assembly kann nicht geladen werden. Rufen Sie die LoaderExceptions-Eigenschaft ab, wenn Sie weitere Informationen benötigen.

In the details there is the information:

{"Die Datei oder Assembly \"EntityFramework, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.":"EntityFramework, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}

This is somehow a bit amazing for me. As far as I know we don't use EntityFramework anywhere, only Telerik as ER.

I have done a "findstr /s /i /m entityframework ." in the projekt directories.

Funilly, it has found it in a Sybase dll "SQL Anywhere 12\iAnywhere.Data.SQLAnywhere.v4.0.dll".

okay - that seems a bit like a sybase sql data provider. But so far as I can see we do not need EntityFramework, and the project also works as anticipated.

How can i resolve this issue? Like saying: I want to parse Appdomain, but not some third party dlls. Or is there any way to ignor the error?

1

1 Answers

5
votes

Parsing whole appdomain in such matter will scan all dlls that are loaded and all types form all of them will be loaded event if they are not used in your application. I'm not fluent in German but I assume that the error means that EF dll was not found. It is required to load some class that is not used by your code and is declared in some dll that is loaded in appdomain and it requires EF. You say you use Telerik, maybe it has some controls that utilize EF directly?

The simple solution if you want to scan only your dlls would be to introduce convention for assembly names. Say all your dlls will be named OfflerCompany.ProjectName.Something and scan dll name for OfflerCompany.

Also note that dlls are lazy loaded to appdomain so if you expect all of your dlls to be present you might be disappointed (there might be there already if all where used directly or not at least once).

You might want to consider crrating configuration file that contains names of all dlls that need to be scanned. This is the cleanest and most transparent solution that I prefer.