C# program using a sphinx4 .jar converted to .dll fails - ikvm

When I try to instantiate the LiveSpeechRecognizer, it throws an error which gives the following stack trace:
Exception thrown: 'edu.cmu.sphinx.util.props.PropertyException' in VoiceRecognition.dll
at edu.cmu.sphinx.frontend.AutoCepstrum.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.ConfigurationManager.lookup(String instanceName)
at edu.cmu.sphinx.util.props.PropertySheet.getComponentList(String name, Class tclass)
at edu.cmu.sphinx.frontend.FrontEnd.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(String name)
at edu.cmu.sphinx.decoder.scorer.SimpleAcousticScorer.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(String name)
at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstSearchManager.newProperties(PropertySheet ps)
at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstLookaheadSearchManager.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(String name)
at edu.cmu.sphinx.decoder.AbstractDecoder.newProperties(PropertySheet ps)
at edu.cmu.sphinx.decoder.Decoder.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.PropertySheet.getComponent(String name)
at edu.cmu.sphinx.recognizer.Recognizer.newProperties(PropertySheet ps)
at edu.cmu.sphinx.util.props.PropertySheet.getOwner()
at edu.cmu.sphinx.util.props.ConfigurationManager.lookup(String instanceName)
at edu.cmu.sphinx.api.Context..ctor(String path, Configuration config)
at edu.cmu.sphinx.api.Context..ctor(Configuration config)
at edu.cmu.sphinx.api.AbstractSpeechRecognizer..ctor(Configuration configuration)
at edu.cmu.sphinx.api.LiveSpeechRecognizer..ctor(Configuration configuration)
at TestingStandaloneCSVoiceRecognition.Program..ctor()
I"ve been trying to sift through the documentation and code to figure out what's causing it, but I've had little luck so far. I should probably note that I used IKVM to convert the .jars to a .dll which I've imported into a Visual Studio C# project. The LiveSpeechRecognizer doesn't even finish instantiating before throwing the error. I've made sure that I've imported all dependencies, so that's not the issue. The java program works fine.

It is a bad idea to call java code from C#, instead you can simply use pocketsphinx dll with C# API, see
https://github.com/cmusphinx/pocketsphinx/tree/master/swig/csharp

Related

Problem when running Azure function locally using Azure Functions Core Tools

I am developing a durable Azure function. I am using .NET Core 3.1. It is an HTTP-triggered function. When I debug it from Visual Studio and then trigger it by calling the endpoint everything works.
On the same machine I installed Azure Functions Core Tools (4.0.3971). I run the storage emulator:
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe start
Then go to the directory where my function resides and type:
func start
Everything works the same as previously, so I trigger my function by making a request to the endpoint. It starts doing its work, but then throws the following error:
[2021-12-03T14:25:51.081Z] Executed 'MyFunction_Process' (Failed, Id=f709e4c0-f74e-4303-a68b-6d5d55f0f7e5, Duration=2182ms)
[2021-12-03T14:25:51.086Z] System.Private.CoreLib: Exception while executing function: MyFunctionIntegration_Process. Microsoft.EntityFrameworkCore: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception. System.Linq: Sequence contains more than one matching element.
[2021-12-03T14:25:51.101Z] myfunctionsingleinstance: Function 'MyFunction_Process (Activity)' failed with an error. Reason: System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception.
[2021-12-03T14:25:51.106Z] ---> System.InvalidOperationException: Sequence contains more than one matching element
[2021-12-03T14:25:51.110Z] at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
[2021-12-03T14:25:51.112Z] at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
[2021-12-03T14:25:51.113Z] at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
[2021-12-03T14:25:51.115Z] at Microsoft.EntityFrameworkCore.EnumerableMethods..cctor()
[2021-12-03T14:25:51.116Z] --- End of inner exception stack trace ---
[2021-12-03T14:25:51.117Z] at Microsoft.EntityFrameworkCore.EnumerableMethods.get_AnyWithPredicate()
[2021-12-03T14:25:51.119Z] at Microsoft.EntityFrameworkCore.Query.Internal.AllAnyToContainsRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
[2021-12-03T14:25:51.121Z] at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
[2021-12-03T14:25:51.124Z] at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
[2021-12-03T14:25:51.126Z] at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
[2021-12-03T14:25:51.128Z] at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
[2021-12-03T14:25:51.129Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
[2021-12-03T14:25:51.131Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
[2021-12-03T14:25:51.133Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.134Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.136Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
[2021-12-03T14:25:51.140Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
[2021-12-03T14:25:51.141Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
[2021-12-03T14:25:51.143Z] at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable`2.GetEnumerator()
[2021-12-03T14:25:51.144Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
[2021-12-03T14:25:51.146Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
[2021-12-03T14:25:51.148Z] at Logistics.Infrastructure.MyFunctionIntegration.Integration.GetDbRows(ILogger log) in C:\Users\Michal\source\repos\Logistics\src\backend\src\infrastructure\Logistics.Infrastructure.MyFunctionIntegration\Integration.cs:line 103
...
The line 103 is:
var dbEntities = _dbContext.Carriers.IgnoreQueryFilters().Include(c => c.CarrierGitd.Address).ToDictionary(c => c.CarrierGitd?.LicenseNumber);
So it happens when I try to fetch data from the database. But it works fine, when I debug in VS. The database is the same. Where's the catch?
The problem went away when I upgraded Microsoft.EntityFrameworkCore to 5.0.0 in SecondLib dependency.
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="5.0.0" />
</ItemGroup>
The TargetFramework wasn't touched
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
Note:
I got the same issue in the Azure Functions core tools version 3. If your Entity framework core version is < 5.x in second lib dependency, upgrade and try once. Or If possible, downgrade Azure Functions Core tools version to 3 and check.
I needed to support both a v3 and v4 functions project so I just took a copy of the V3 tools directory C:\Program Files\Microsoft\Azure Functions Core Tools (then named it something like 'Azure Functions Core Tools v3'), installed V4 and created a batch file to run the correct 'func.exe' in the directory for the old v3 project.

Xamarin Forms Release Problem: Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.Net.Http.Headers.DateTimeFormatter

I'm kinda new to xamarin. I got this error when I'm switching from debug mode to release mode, I search everywhere but I got no answer.
Severity Code Description Project File Line Suppression State
Error Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.Net.Http.Headers.DateTimeFormatter::ToRfc1123String(System.DateTimeOffset,System.Boolean)' in assembly: 'Microsoft.Net.Http.Headers.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve Microsoft.Extensions.Primitives.InplaceStringBuilder
at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17"
Trevor answer worked for me, but there is alternative solution.
I've noticed that this missing class Microsoft.Extensions.Primitives.DateTimeFormatter was removed from Microsoft.Extensions.Primitives dll in version 4.0. Some of dependencies to my project required version >=3.2 and some >=5.0. I guess linker chosen to link higher 5.0 version so the other dependency failed to find removed class.
Solution is to update all dependencies so their dependencies uses versions of Microsoft.Extensions.Primitives >=5.0
Turning linking off is the lazy answer. The point of using the linker is to remove "dead" code and minimize the size of the program. The size of a mobile app is more important to many users.
The linker used in Xamarin.Android is going to remove code it thinks you are not using. This is especially true when using reflection. To fix this you would need to tell the compiler you're using the type.
A popular solution is to use a LinkerPleaseInclude.cs file and make stub methods using the type and properties so the compiler thinks you're using them. You will find many examples on the Internet.
public class LinkerPleaseInclude
{
public void KeepInplaceStringBuilder(Microsoft.Extensions.Primitives.InplaceStringBuilder x)
{
x.Append('x'); // This will keep the InplaceStringBuilder.Append method from being linked out...
}
}
A newer solution is to use a Custom Linker Configuration XML file. This is a bit less of a "hack" than the LinkerPleaseInclude.cs solution, but more verbose. It allows you to preserve the whole type, specific methods, properties, etc.
<linker>
<assembly fullname="Microsoft.Net.Http.Headers">
<type fullname="Microsoft.Extensions.Primitives.InplaceStringBuilder">
</assembly>
</linker>
Either solution will work. Just keep doing this for each of the types the linker complains about and it will eventually work.

What are the valid DNX --watch flag values?

I'm working on my first ASP.NET 5 application. When trying to start the application from the command line by running:
dnx web --watch
I get the following output:
System.FormatException: Value for switch '--watch' is missing.
at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Add(IConfigurationProvider provider)
at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args)
at Microsoft.AspNet.Server.Kestrel.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
What are the valid values for the --watch flag? I tried giving it a dummy value of 0 then changed some of my controller code, but the change was not reflected.
Update
To install dnx-watch run the following:
dnu commands install Microsoft.Dnx.Watcher
Then run your application by doing something like:
dnx-watch web
Arguments passed after the command name ("web" in your case) are arguments passed to that command. If you want arguments passed to DNX, pass them before: dnx --watch web
But, --watch will go away. Use dnx-watch instead: https://github.com/aspnet/Announcements/issues/74

Is there shorter way to work with dotnetnuke and SVN

I have one project with a few sub projects in it. A few projects contain dotnetnuke modules. And I have committed this project to SVN repo. But now when I checkout version from SVN I have to manually copy module project to dotnetnuke/desktopModules directory. I am trying to find some shorter way for this :(
I follow solution from this question DotNetNuke and Subversion guidelines , but have no luck. I added nant.build file to my project with dotnetnuke modules. Navigate to it from command line and run 'nant' command, but I got following error :(
Unhandled Exception:
System.TypeInitializationException:
The type initializer fo r
'NAnt.Console.ConsoleStub' threw an
exception. --->
System.Security.SecurityEx ception:
Request for the permission of type
'System.Security.Permissions.FileIOP
ermission, mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c5619 34e089'
failed. at
System.Security.CodeAccessSecurityEngine.Check(Object
demand, StackCrawlMa rk& stackMark,
Boolean isPermSet) at
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, S tackCrawlMark& stackMark) at
System.Security.CodeAccessPermission.Demand()
at
System.AppDomainSetup.VerifyDir(String
dir, Boolean normalize) at
System.AppDomain.get_BaseDirectory()
at
log4net.Config.XmlConfiguratorAttribute.Configure(Assembly
sourceAssembly, ILoggerRepository
targetRepository) at
log4net.Core.DefaultRepositorySelector.ConfigureRepository(Assembly
assemb ly, ILoggerRepository
repository) at
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositor yAssembly, Type
repositoryType, String repositoryName,
Boolean readAssemblyAttri butes) at
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositor yAssembly, Type
repositoryType) at
log4net.Core.DefaultRepositorySelector.GetRepository(Assembly
repositoryAs sembly) at
log4net.Core.LoggerManager.GetLogger(Assembly
repositoryAssembly, String n ame)
at
log4net.LogManager.GetLogger(Assembly
repositoryAssembly, String name) at
log4net.LogManager.GetLogger(Type
type) at
NAnt.Console.ConsoleStub..cctor()
--- End of inner exception stack trace --- at NAnt.Console.ConsoleStub.Main(String[]
args)
To address your first point, if you map your source control repository directly to your website's desktopmodules folder, you won't need to copy it manually after getting latest.
For the second point, you may need to unblock the files being used by NAnt or look into using a different version of NAnt that does not have this issue. Alternatively, you can look into using MSBuild scripts instead of NAnt.

error ASPPARSE: Could not load type

If I run this command on my system
<Exec Command="C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -v localhost -p $(SourceDir)\wwwroot -u -f projectCompileCode\project -c -errorstack -nologo" />
I get the following error:
error ASPParse: Could not load the type: Projectname:SomeFile.
The project is web application project
This my stack trace:
[HttpException]: Could not load type 'ProjectName.FileName'.
at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCa
e, Boolean throwOnError)
at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeN
me, String codeFileBaseTypeName, String src, Assembly assembly)
at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDicti
nary parseData)
[HttpParseException]: Could not load type ''ProjectName.FileName.
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virt
alPath, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseReader(StreamReader reader, VirtualP
th virtualPath)
at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPat
virtualPath)
at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse()
at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType(
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(
uildProvider buildProvider)
at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResu
t(Boolean isPrecompiledApp)
at System.Web.Compilation.BuildManager.CompileGlobalAsax()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath
tartingVirtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath starting
irtualDir)
at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCa
lback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManag
rCallback callback)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManag
rCallback callback)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(Client
uildManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(Client
uildManagerCallback callback)
at System.Web.Compilation.Precompiler.Main(String[] args)
If I build in v2.0.50727 then still it is giving the same error.
My application is built in with VS 2010, .net frame asp.net frame work 4
Any help is greatly apperciated.
Have you tried:
Checking references
Doing a clean and a build
Checking the Inherits attr in the HTML against the code behind
Creating a new App Pool in IIS for this web site?
I see a similar problem. Works locally from within VS2008, but once published and deployed to the server, I get the same error as described here.
None of the suggestions I have provided worked for me; maybe they will work for you.
I had the same error. When I opened the web site DLL in ILDASM, the Type for a control was completely missing, as if it didn't even get compiled.
As it turns out, the codebehind files got excluded from the project. This is strange considering that the builds on my machine were successful! At any rate, I carefully re-included codebehind files and it all started working.
This often happens because the project file (.csproj or .vbproj) does not contain the necessary references to the files in question. Try cleaning/rebuilding all projects and making sure that the latest project files are moved to the server as well.
Another possibility is that the file was not actually included in your project at all. This allows the builds in Visual Studio to run just fine, but will break when compiling the .NET code (with aspnet_compiler for example) because all .aspx/.ascx/etc. files within the specified folder are compiled - whether they are included in your project or not.

Resources