> Set the OutputAssembly property on the CompilerParameters.
> > Set the OutputAssembly property on the CompilerParameters.
>
[quoted text clipped - 4 lines]
> but this does not cause error. So it seems that this parameter is not used
> in in-memory assembly generation.
That's not necessarily the case. What was the generated assembly name
(when you ask the Assembly object itself) in this case?
> How to force XmlSerializer() to find dynamically loaded assembly ?
At this stage it's beyond my knowledge, I'm afraid.
> > By the way, if you're using C# 3 you should really look at using
> > object/collection initializers more - you're code would be a *lot*
[quoted text clipped - 19 lines]
> collection initializer because it does not implement
> 'System.Collections.IEnumerable'
Indeed. If you look at your original code, you don't try to add strings
to the CompilerParameters directly - you add them to the referenced
assemblies.
> How I can use object/collection initializers more ?
// Earlier, on one line:
const string ReferenceBase35 = @"c:\Program Files\Reference Assemblies
\Microsoft\Framework\v3.5\";
CompilerParameters compilerParameters = new CompilerParameters
{
GenerateInMemory = true,
ReferencedAssemblies =
{
"DataAccessBase.dll",
"Entity.dll",
"dblinq.postgresql.dll",
"dblinq.dll",
"System.dll",
ReferenceBase35+"System.Data.Linq.dll",
ReferenceBase35+"System.Core.dll",
"System.Data.dll",
"System.Xml.dll"
}
};
Much clearer, if I do say so myself :)
(Untested, mind you...)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Andrus - 28 Feb 2008 18:14 GMT
Jon,
> That's not necessarily the case. What was the generated assembly name
> (when you ask the Assembly object itself) in this case?
I was wrong. It changes the in-memory assembly name.
OutputAssembly = "EntityExtension";
Generates assembly name
CompiledAssembly = {EntityExtension, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null}
However XmlSerializer() call still causes exception. In this exception
assembly name is the same:
Message="Unable to generate a temporary class (result=1).\r\nerror CS0012:
The type 'MyApp.EntityExtension.Kontekst' is defined in an assembly that is
not referenced. You must add a reference to assembly 'EntityExtension,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.\r\n"
So assembly names seems to be same.
>> How to force XmlSerializer() to find dynamically loaded assembly ?
>
> At this stage it's beyond my knowledge, I'm afraid.
Exception occurs in
System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns,
XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
So XmlSerializer() uses dynamic compilation and this fails to resolve
dynamically loaded assembly.
> // Earlier, on one line:
> const string ReferenceBase35 = @"c:\Program Files\Reference Assemblies
> \Microsoft\Framework\v3.5\";
Excellent! Thank you very much.
In customer computer framework may be installed to directory than this.
How to determine the location of
c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\
in customer computer ?
Andrus.
Jon Skeet [C# MVP] - 28 Feb 2008 18:46 GMT
<snip>
> >> How to force XmlSerializer() to find dynamically loaded assembly ?
> >
[quoted text clipped - 7 lines]
> So XmlSerializer() uses dynamic compilation and this fails to resolve
> dynamically loaded assembly.
Mmm... one for more of an XML serialization expert, I'm afraid.
> > // Earlier, on one line:
> > const string ReferenceBase35 = @"c:\Program Files\Reference Assemblies
[quoted text clipped - 8 lines]
>
> in customer computer ?
Have a look in the registry at key
HKLM\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\v3.5 and value
"All Assemblies In".

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Andrus - 29 Feb 2008 08:08 GMT
Jon,
>> c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\
>>
[quoted text clipped - 4 lines]
> HKLM\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\v3.5 and value
> "All Assemblies In".
Why those assemblies are not put onto GAC ?
Looks very inconvenient to treat some assemblies differently than others.
Andrus.
Jon Skeet [C# MVP] - 29 Feb 2008 08:45 GMT
> >> c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\
> >>
[quoted text clipped - 7 lines]
> Why those assemblies are not put onto GAC ?
> Looks very inconvenient to treat some assemblies differently than others.
They *are* in the GAC. (Have a look in the GAC to verify - they're
certainly in my GAC.) They're also in the reference assemblies
directory so they're visible as actual files. (This is kinda handy when
it comes to using Reflector, for instance...)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Andrus - 29 Feb 2008 14:30 GMT
Jon,
> They *are* in the GAC. (Have a look in the GAC to verify - they're
> certainly in my GAC.)
If so then dynamic compile must find them without directory prefix.
Why those assemblies require using directory prefix to be usable from
dynamic compile ?
> They're also in the reference assemblies
> directory so they're visible as actual files. (This is kinda handy when
> it comes to using Reflector, for instance...)
Why this directory exists and contains only those particular files?
Is it only for Reflector ?
Is so why other assemblies are not provided in this way ?
Andrus.
Jon Skeet [C# MVP] - 29 Feb 2008 14:38 GMT
> > They *are* in the GAC. (Have a look in the GAC to verify - they're
> > certainly in my GAC.)
>
> If so then dynamic compile must find them without directory prefix.
I'd have expected it to - at least if you specify the full assembly
name including version.
> Why those assemblies require using directory prefix to be usable from
> dynamic compile ?
Not sure. Try the full name.
> > They're also in the reference assemblies
> > directory so they're visible as actual files. (This is kinda handy when
[quoted text clipped - 3 lines]
> Is it only for Reflector ?
> Is so why other assemblies are not provided in this way ?
I think they've been moving towards this model rather than keeping them
in c:\Windows\Microsoft.NET\framework\vXXX

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Andrus - 29 Feb 2008 17:53 GMT
Jon,
>> Why those assemblies require using directory prefix to be usable from
>> dynamic compile ?
>
> Not sure. Try the full name.
http://msdn2.microsoft.com/en-us/library/s5bac5fx.aspx describes that
reference directory is *not* included in compiler default search
directories:
The compiler searches for assembly references that are not fully qualified
in the following order:
1.. Current working directory. This is the directory from which the
compiler is invoked.
2.. The common language runtime system directory.
3.. Directories specified by /lib.
4.. Directories specified by the LIB environment variable
It seems that they forget to include reference directory to compiler default
search path in 3.5.
Andrus.
Andrus - 29 Feb 2008 17:54 GMT
Jon,
>> Why those assemblies require using directory prefix to be usable from
>> dynamic compile ?
>
> Not sure. Try the full name.
http://msdn2.microsoft.com/en-us/library/s5bac5fx.aspx describes that
reference directory is *not* included in compiler default search
directories:
The compiler searches for assembly references that are not fully qualified
in the following order:
1.. Current working directory. This is the directory from which the
compiler is invoked.
2.. The common language runtime system directory.
3.. Directories specified by /lib.
4.. Directories specified by the LIB environment variable
It seems that they forget to include reference directory to compiler default
search path in 3.5.
Can we put this to wishlist ?
Andrus.
Jon Skeet [C# MVP] - 29 Feb 2008 19:03 GMT
> Jon,
>
[quoted text clipped - 20 lines]
>
> Can we put this to wishlist ?
I don't think the reference directory is *really* meant for that
purposee. You'd be better off loading it from the GAC with the full
name, IMO.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk