反射加载组件奇怪的错误

时间:2016-10-29 16:46:08

标签: c# mono .net-assembly

我尝试使用此代码在某个字符串(SpeechSynthesizer.SpeakAsync)上调用GetVerbatim(text)方法:

System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom("System.Speech.dll");
System.Type type = assembly.GetType("System.Speech.Synthesizer.SpeechSynthesizer");
var methodinfo = type.GetMethod("SpeakAsync", new System.Type[] {typeof(string)} );
if (methodinfo == null) throw new System.Exception("No methodinfo.");

object[] speechparameters = new object[1];
speechparameters[0] = GetVerbatim(text); // returns something like "+100"

var o = System.Activator.CreateInstance(type);
methodinfo.Invoke(o, speechparameters);

但它正在抛出这个巨大的错误:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullRe
  at System.Speech.Internal.ObjectTokens.RegistryDataKey.HKEYfromRegKey (Microsoft.Win32.RegistryKey regKey) <0x43da0b0 + 0x00034> in <filename unknown>:0 
  at System.Speech.Internal.ObjectTokens.RegistryDataKey.RootHKEYFromRegPath (System.String rootPath) <0x43d9e08 + 0x00027> in <filename unknown>:0 
  at System.Speech.Internal.ObjectTokens.RegistryDataKey.Open (System.String registryPath, Boolean fCreateIfNotExist) <0x43d9bc0 + 0x0009b> in <filename unknown>:0 
  at System.Speech.Internal.ObjectTokens.ObjectTokenCategory.Create (System.String sCategoryId) <0x43d9b50 + 0x0001b> in <filename unknown>:0 
  at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut () <0x43d9978 + 0x0002f> in <filename unknown>:0 
  at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor (System.WeakReference speechSynthesizer) <0x43d8818 + 0x007a3> in <filename unknown>:0 
  at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer () <0x43d8708 + 0x0006b> in <filename unknown>:0 
  at System.Speech.Synthesis.SpeechSynthesizer.SpeakAsync (System.Speech.Synthesis.Prompt prompt) <0x43d85c0 + 0x00033> in <filename unknown>:0 
  at System.Speech.Synthesis.SpeechSynthesizer.SpeakAsync (System.String textToSpeak) <0x43d8210 + 0x00063> in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.Cultu
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.Cultu
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x188adb0 + 0x00046> in <filename unknown>:0 
  at ScriptLoader.Script+DMTBot.GetText (System.String text) <0x43d2128 + 0x0014f> in <filename unknown>:0 
  at MinecraftClient.McTcpClient.OnTextReceived (System.String text) <0x43954d0 + 0x0005e> in <filename unknown>:0

0 个答案:

没有答案