On Feb 11, 9:58*am, Jeroen Mostert <jmost...@newsgroup> wrote:
> On 2010-02-10 22:20, Jonathan Gilbert wrote:
>
> > I work for a company that sells .NET software and have recently been
> > tasked with handling support issues to do with our updatesystem,
> > which I wrote. Since the updater is the first thing that runs when the
> > desktop icon is clicked, I also get unrelated issues, and one that has
> > been coming up repeatedly is the following exception while trying to
> > instantiate an XmlSerializer: >
> >System.TypeInitializationException: The type initializer for
> > 'IQ.Core.UpdateFoundation.Dispatcher.DispatchRequest' threw an
> > exception. ---> *System.BadImageFormatException: Could not load file or
> > assembly '0bytesloadedfromSystem, Version=2.0.0.0,
> > Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
> > dependencies. An attempt was made to load a program with an incorrect
> > format. >
> http://support.microsoft.com/kb/919825is not your scenario, but it might
> have the same root cause (an invalid assembly generating a misleading error
> message). The trouble is figuring out which assembly. Try using procmon
> (http://technet.microsoft.com/en-us/s.../bb896645.aspx) to identify
> the failing assembly as it's beingloaded. You can use peverify.exe to check
> if it's valid. It might be your own assembly, being corrupted as it's
> downloaded.
>
> However, if a complete reinstall of the .NET Framework doesn't help and it
> also affects .NET software other than your own, this suggests no single
> assembly is the problem. Reboot into safe mode and see if the problem still
> occurs. File-systemfilter drivers like the ones installed by antivirus
> programs can prevent successful file access. Process Monitor should be able
> to see this as well, though it may not be as obvious.
>
> --
> J. Thanks for this information. With it, and armed with the stack trace
in the original post, I wrote a simple test app:
CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
CompilerResults results = provider.CompileAssemblyFromSource(
new CompilerParameters()
{
GenerateExecutable = true,
GenerateInMemory = false,
IncludeDebugInformation = false,
OutputAssembly = "Test",
},
@"using System;
class Test
{
static void Main()
{
Console.WriteLine(""It worked!"");
}
}");
This returns without errors, but as soon as I access the
CompiledAssembly property of the CompilerResults object, I immediately
get:
System.IO.FileNotFoundException: Could not load file or assembly
'file:///C:\Tes
tApp\Test' or one of its dependencies. The system cannot find the file
specified
..
File name: 'file:///C:\TestApp\Test'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark,
Boolean forIntrospection)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef,
Evidence assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
This brings things into clarity; the error is that CSC is not working,
and the "0 bytes loaded from System", in which the filename is wrong,
is merely a symptom of this.
I will follow up if/when I discover why CSC isn't working.
Thanks for your suggestions. Disabling anti-virus software and running
in safe mode will be the first things I try next.
Jonathan