Error - Unable to load ai model in c# application - c#

I tried to run a c# application which use an image classification model, but when I try to load the image, the program crashes with the following error:
System.ArgumentException: 'The parameter is incorrect.
Failed to load model with error: Unknown model file format version.'
This is the function that loads the model into memory:
private async Task loadModel()
{
// Get an access the ONNX model and save it in memory.
StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/Model.onnx"));
// Instantiate the model.
modelGen = await Model.CreateFromStreamAsync(modelFile);
}

Related

In Xamarin.Android getting resource id "Android.Content.Res.Resources+NotFoundException:" error occur

I want to get id(int) for audio file from Asset folder but it give me error.
var File_Id = Resources.GetIdentifier("my_file.ogg","Assets", PackageName);
Above line of code execute in android Service
it give error,
Error Log:
03-13 14:03:50.047 W/ResourceType(13170): No package identifier when getting value for resource number 0x00000000
Unhandled Exception:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
this file "my_file.ogg" is in "Asset" folder ,build action set to "AndroidAsset"
The asset can be read using the AssetsManager. Try below code snippet to read file from asset.
Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd("File name");
Updated Answer :
The following code snippet will help to play media file directly from the Asset folder.
Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd(fullPath);
if (afd != null )
{
player.SetDataSource (afd.FileDescriptor, afd.StartOffset, afd.Length);
player.Prepare ();
player.Start ();
}
In my case, I had a Xamarin Forms project. I had included a resource in the iOS project which the xaml page was referring to, but forgot to include it in the Android project.

Error with com reference in WCF with dll done in VFP

I have a dll done in VFP that I need to use to be able to perform some processes in the DBF, I add the normal reference, I can use the class in my WCF project.
public API _api;
var _api = new API();
_api.version();
When I make the first call it works fine, but when I make the other call to the service the following error appears:
Failed to create an instance of the COM component with CLSID {FD80E726-1A66-
4823-9D96-D6F00C8B2665} from IClassFactory due to the following error:
80004005 Unspecified error (Exception of HRESULT: 0x80004005 (E_FAIL)).
I do not know what could happen when the class returns.
public Document PostDocument(Document document)
{
var _api = new API();
_api.importar();
return document;
}

How to setup JsReport .NET to use current app folder

Is there way to setup JsReport to use current application folder for storing temp files. Not using common folder C:\Windows\Temp\jsreport? If there are multiple applications running on common IIS, it produces Errors.
Error rendering report: A critical error occurred while trying to execute the render command: An error occurred while trying to start daemonized process: An error has occurred when trying to initialize jsreport (2). EBUSY: resource busy or locked, open 'C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll' (1). caused by error (2) -> stack = Error: at instance.init.then.catch ([eval]:43623:29) at tryCatcher (jsreportRuntime.js:146030:23) at Promise._settlePromiseFromHandler (jsreportRuntime.js:145723:31) at Promise._settlePromise (jsreportRuntime.js:145780:18) at Promise._settlePromise0 (jsreportRuntime.js:145825:10) at Promise._settlePromises (jsreportRuntime.js:145900:18) at Async._drainQueue (jsreportRuntime.js:41845:16) at Async._drainQueues (jsreportRuntime.js:41855:10) at Immediate.Async.drainQueues (jsreportRuntime.js:41729:14) at runCallback (timers.js:794:20) at tryOnImmediate (timers.js:752:5) at processImmediate [as _immediateCallback] (timers.js:729:5)caused by error (1) -> meta = {"errno":-4082,"code":"EBUSY","syscall":"open","path":"C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll"}, stack = Error: (1). caused by error (1) -> stack = Error: at exports.NsSocket.socket.dataOnce ([eval]:44008:13) at exports.NsSocket.listener ([eval]:16744:10) at exports.NsSocket.EventEmitter.emit ([eval]:16832:22) at exports.NsSocket._onData ([eval]:86359:8) at Lazy. ([eval]:51602:13) at Lazy. ([eval]:51584:19) at emitTwo (events.js:126:13) at Lazy.emit (events.js:214:7) at Lazy. ([eval]:51585:22) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7) at yieldTo ([eval]:51692:18) at Function. ([eval]:51730:27) at Lazy. ([eval]:51698:21) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7)
It needed to be configured in FilterConfig in RegisterGlobalFilters, so it creates jsreport folder in current app folder, so jsreport.exe do not interfere with other instances. Key property is TempDirectory, which define location for temporary folder. All files within this TempDirectory is created automatically.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
var tempPath = Path.Combine(HttpRuntime.AppDomainAppPath, "jsreport");
filters.Add(new JsReportFilterAttribute(new LocalReporting()
.Configure(cfg =>
{
cfg.BaseUrlAsWorkingDirectory();
cfg.TempDirectory = tempPath;
return cfg;
})
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.Create()));
}

C# How to get the current Page Coded UI TEST in Wpf

I want to know if it's possible to get / know the current page in wpf.
In my project, I put this code and I have the correct page:
var current_page = (Window.Current.Content as Frame).Content.GetType();
Windows.Current.Content was null.
But in my UI Test project, I have the following error:
Result Message:
Test method CodedUITestProject1.CodedUiTest.CodedUITestMethod1 threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

XNA MediaPlayer ContentLoadException was unhandled

I want to use the MediaPlayer object to play one background song. Everything is fine until I try to start the program.
I have seen people using only two lines of code in order to play a song, this is what I do in the LoadContent method:
Song song = Content.Load<Song>("song");"song_title"
MediaPlayer.Play(song_title);
I get this in error
Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
HResult=-2146233088
Message=Error loading "song". File contains Microsoft.Xna.Framework.Audio.SoundEffect but trying to load as Microsoft.Xna.Framework.Media.Song.

Categories