[英]System.EntryPointNotFoundException in Parallel red in output
I had some minor problem but I cant seem to see where its gone wrong , could someone help me out: 我遇到了一些小问题,但是我似乎看不到哪里出了问题,可以有人帮我解决一下:
Loadassembly fn 负载装配fn
public static Assembly LoadAssembly(string assemblyfile)
{
Assembly library;
using (var fs = File.Open(assemblyfile, FileMode.Open))
{
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[1024];
int read;
while ((read = fs.Read(buffer, 0, 1024)) > 0)
ms.Write(buffer, 0, read);
library = Assembly.Load(ms.ToArray());
}
}
return library;
}
public static string[] GetDLLInfo(string assemblyfile, bool onlyNameSpace)
{
var strAssembly = LoadAssembly(assemblyfile).GetTypes();
List<string> classList = new List<string>();
var xx = strAssembly.Select(t => t.Namespace).Distinct().ToList();
var nmSpaceLiStrings = xx.ToArray();
Parallel.ForEach(nmSpaceLiStrings, x =>
{
var types = strAssembly.Where(t => t.IsClass && t.Namespace == x).ToList();
types.ForEach(t => classList.Add(t.FullName));
});
/* foreach (var x in nmSpaceLiStrings)
{
var types = strAssembly.Where(t => t.IsClass && t.Namespace == x).ToList();
types.ForEach(t => classList.Add(t.FullName));
} */
if (onlyNameSpace)
{
return nmSpaceLiStrings;
}
return classList.ToArray();
}
Its kind of weird if I use 'foreach' (not parallel , I got no warning in output dialog, but when I use 'parallel' I got : 如果我使用'foreach'(不是parallel,那有点奇怪,在输出对话框中没有警告,但是当我使用'parallel'时,我得到了:
A first chance exception of type 'System.EntryPointNotFoundException' occurred in mscorlib.dll
Does my parallel gone wrong and show me the correct way? 我的平行测试是否出错并向我显示正确的方法?
Thanks in advance . 提前致谢 。
您没有尝试使用ConcurrentBag <T>来代替将类名添加到列表中吗?
What is LoadAssembly method? 什么是LoadAssembly方法? How it's declared? 如何声明? The exception means that some method does not exist in the dll. 该异常表示dll中不存在某些方法。 So the problem is in the assembly itself or in the LoadAssembly declaration. 所以问题出在程序集本身或LoadAssembly声明中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.