CodeGuru Forums

CodeGuru Forums (http://www.codeguru.com/forum/index.php)
-   C-Sharp Programming (http://www.codeguru.com/forum/forumdisplay.php?f=11)
-   -   HowTo test an Assembly for Manifest (http://www.codeguru.com/forum/showthread.php?t=420604)

ireland April 12th, 2007 10:51 AM

HowTo test an Assembly for Manifest
 
How does one test an Assembly for a Manifest?

I have one assembly in my domain which throws a BadImageFormatException when Assembly.Load is used, I think it's because it has no Manifest information, the exception details say " The module was expected to contain an assembly manifest.", how can I check for this first in order to prevent an Exception?

Could not load file or assembly 'file:///C:\Program Files\ProjectAggregator.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

mcmcom April 12th, 2007 11:09 AM

Re: HowTo test an Assembly for Manifest
 
im not 100% sure on this but i think the assembly needs a manifest in order to function properly. That being said i dont know how to test to see if its there but i suspect that without it the assembly will not work anyways. If this is YOUR assembly you should look at re-compiling it and make sure your including your AssemblyInfo.cs (or .vb) file. If its not yours you should contact whoever gave it to you and see if you can get an updated version.

Heres some info on the Assembly and Manifests: http://blogs.msdn.com/trobbins/articles/404939.aspx

Also here is a blog entry by a guy who had a similar problem, the cause was a minor flaw in the code of his loaded assembly, maybe it can spark some thoughts on a possible solution

http://blog.devstone.com/aaron/archive/2006/06/21.aspx

hth,
mcm

MadHatter April 12th, 2007 11:25 AM

Re: HowTo test an Assembly for Manifest
 
bad image format exceptions usually happen when you try to load a non-.net assembly, or if you try to load a .net 2.0 assembly in 1.x.

ireland April 12th, 2007 11:58 AM

Re: HowTo test an Assembly for Manifest
 
Thanks guys,
I'm using .NET 2.0 but the assembly comes from Visual Studio SDK I think, not sure what's so unique about the exception though, this is a forum thread on the assembly in question:
http://msdn2.microsoft.com/en-us/lib...58(vs.80).aspx

I'd be interested in a generic solution however..if it's a non .NET assembly is there anyway to test from code?

MadHatter April 12th, 2007 02:34 PM

Re: HowTo test an Assembly for Manifest
 
you can always open the file and check its format.

ireland April 13th, 2007 05:00 AM

Re: HowTo test an Assembly for Manifest
 
Now that's what I call a detailed description.
So to test programatically if an assembly is .NET or not, there is no clean solution, try to load the assembly and catching the exception is a workaround.
Code:

try
                    {
                        Assembly *** = Assembly.LoadFrom(fileName);
                    }
                    catch (BadImageFormatException e)
                    {
                      //Deal with exception
                    }


MadHatter April 13th, 2007 11:19 AM

Re: HowTo test an Assembly for Manifest
 
thats what I've done in the past.

I've thought of writing a managed assembly inspector (or file inspector) that could be used to determine if the file as a .NET assembly or not, but haven't had the time to do it. I know reflector doesn't use reflection to load what it has, it reads the file using the stuff explained in that article.

MadHatter April 17th, 2007 04:08 PM

Re: HowTo test an Assembly for Manifest
 
I read this article a while back, but forgot that he does the assembly detection stuff in there, so though its probably too late for what you're working on, here's how its done:

http://www.codeproject.com/csharp/Au...r.asp#validCLR

ireland April 18th, 2007 04:39 AM

Re: HowTo test an Assembly for Manifest
 
Good stuff MadHatter, I presume that's pretty robust. The Try/catch will do in my case but it's nice to know.


All times are GMT -5. The time now is 01:56 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.