I'm currently using the below code within a winform which is generated and compiled programmatically by another application, during this process I embed an assembly in the winform's resources so that it doesn't need an external reference. The the below code is called whenever we attempt to resolve an assembly and instead loads it from the resources.
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = "AssemblyLoadingAndReflection." +
new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
};
The problem however is that this only seems to work in .net 4 and ideally I need this to work开发者_Python百科 in .net 2 so that the created winform can be sent to clients, as the .net 2 framework is installed with windows but .net 4 is not. How could I achieve the same result in .net 2?
The lambda syntax is not supported by C# 2. Use
AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, AssemblyResolveEventArgs args) {
...
};
精彩评论