问题
I have written a small app in C# which works no problem. Target Framework is .NET 4.
When I run the app under linux - mono , the app starts no problem.
However I seem to be having a problem with Threading under mono.
Code below:
try
{
Thread oThread = new Thread(new ParameterizedThreadStart(this.SendSms));
oThread.IsBackground = true;
oThread.Start(_data);
while (!oThread.IsAlive)
{
Console.WriteLine("Sleeping...");
Thread.Sleep(1);
}
}
catch (TypeLoadException tlex)
{
Console.WriteLine("TypeLoadException: " + tlex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
It doesn't seem to get to the SendSms method, but instead throws the following error:
Unhandled Exception: system.TypeLoadException: A type load exception has occurred. at System.Threading.Thread.StartUnsafe () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred. at System.Threading.Thread.StartUnsafe () [0x00000] in <filename unknown>:0
Now I am new to Mono so don't know firstly why this unhandled exception is occuring as the code for the parameterized thread comes from 'http://www.mono-project.com/ThreadsBeginnersGuide'. And secondly, why is it unhandled when i put in the catch (TypeLoadException tlex)
Please assist.
Thanks
Neill
回答1:
may be this answer can help you ..
Mono-LibreOffice System.TypeLoadException
have you tried to compile the same program under mono and tried running it ??
Also which version of mono are you using?? may need to update it to the latest.
mono --version
v 2.10 looks to be the latest stable release.
http://www.go-mono.com/mono-downloads/download.html
回答2:
I had a similar problem on a web server running debian squeeze. This post gave me a clue.
I set up a virtual machine and installed the whole monodevelop using apt-get and it worked. Since I did not want to install that many packages and dependancies on a production machine, I spent a few hours isolating the missing packages.
In my case, they were only 3 missing packages (libmono-system-xml-linq4.0-cil , libmono-system-componentmodel-dataannotations4.0-cil and libmono-system-componentmodel-composition4.0-cil), but of course it will depend on your application.
According to the error message, it was not easy to figure out the solution !
回答3:
Although the problem was fixed by installing missing packages, I noticed you could also get this error when referencing DLL's through Nuget: Monodevelop did not copy these DLL's to the output folder (i.e. /bin/Debug) which made my program unable to run. The debugger couldn't even step into the first line of code! This occurred to me on Ubuntu 16.04. Check your output folder, and if you notice some DLL's are missing you should try to copy them manually and see if your application runs now.
来源:https://stackoverflow.com/questions/12642333/unhandled-exception-system-typeloadexception-when-running-on-mono-compiled-on