1

I have a huge project written in c# using .Net 3.5 I need to use Unity3D for my project. I tried to import Unity into my project but I found out that it is not possible. So, now I want to import the code that I have written in C# into Unity. I created a library using the code that I already have, to import it into Unity and use it. But when I try to import it I receive the following error:

Unhandled Exception: System.TypeLoadException: Could not load type 'SpeechTools.ClsSpeechSynthesis' from assembly 'MySpeechSynthesizer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Could not load file or assembly 'System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

I am using System.Speech in my library. It is not supported in Unity (Mono). I guess the problem is caused by this dependency.

Can anyone help me? Is there a way to write a wrapper around System.Speech.SpeechSynthesizer and use it in Unity?

I searched online and I found a lot of tutorials on writing wrappers for c++ codes but nothing for c# and .Net libraries.

2
  • In a micro services era, you can easily write a micro service and run it on .NET Framework 3.5 (why not upgrade to .NET 4.5.2 and above?), and then consume the service in a Unity application. There is really no need to merge them together and hit such nobody-care issues. Commented Jan 16, 2016 at 3:37
  • So you suggest that I write a service and use it in unity? instead of trying to write a wrapper around system.speech? Commented Jan 16, 2016 at 23:06

1 Answer 1

1

System.Speech is not supported by Unity's version of Mono, so you're out of luck. You also can't just drop in the Windows version of the System.Speech DLL since it probably won't work with Unity's version of Mono.

You can't write a C# wrapper DLL that uses System.Speech either because that is essentially the same as dropping the DLL straight in. Unity's Mono will try to load it and fail.

You'll have to find either a native library that implements the feature you want and write a wrapper around that, or write an implementation entirely in C#.

You could potentially write a native wrapper (i.e. in C++) around the C# DLL. This wrapper would initialise the CLR and load the C# DLL. Then the native wrapper would be referenced in Unity. You would have to expose the entire System.Speech API through this native wrapper. I think this would work, but it is pretty cumbersome and would only work on Windows or platforms where .NET is available (i.e. no web player, mobile, Linux, OS X).

Sign up to request clarification or add additional context in comments.

1 Comment

Is it possible to write a wrapper for system.speech and use it in unity?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.