nickdu088 / SharpExt4

A .Net library to provide full access (read/write) to Linux ext2/ext3/ext4 filesystem
https://www.nickdu.com/?p=890
42 stars 9 forks source link

Could not load file or assembly 'SharpExt4, Version=1.0.8402.18282 #16

Closed kuttikrishnan closed 1 year ago

kuttikrishnan commented 1 year ago

Tried to reference this project to a dotnet core based project (a dotnet core console application), Then I am getting an issue as mentioned below. It will be great if you are able to help me to fix the same.

Could not load file or assembly 'SharpExt4, Version=1.0.8402.18282, Culture=neutral, PublicKeyToken=null'. Format of the executable (.exe) or library (.dll) is invalid.

nickdu088 commented 1 year ago

you need to specify the .net core application x86 or AMD64 based on your machine.

kuttikrishnan commented 1 year ago

Hi , Thanks for your comments. Changing the platform target x86, solved the DLL issue which I mentioned earlier. Now I am able to reference the SharpExt4 project in the dotnetcore console application and run it.

But actually, I wanted to reference the same project (SharpExt4 ) in the .net MAUI application and work. As per your previous comment, I changed the MAUI platform target to x86 and hence I am not getting the DLL issue that I mentioned earlier. But I am getting another issue (as mentioned below) in the c++ project (ExtDisk.CPP line #116)

_Inspection of unmanaged type 'ext4blockdev*' requires unmanaged debugging to be enabled. Please set the debugger type to 'Mixed' and try again

Screenshot : https://drive.google.com/file/d/1E2dIMawnxe0DBc9sx-f-bpB2Y0f9Pv3l/view?usp=share_link

It will be very helpful if you are able to help me to resolve this issue.

Thanks and Regards, Kutti

nickdu088 commented 1 year ago

.net MAUI and .net console should be the same. If console application runs well, MAUI should also runs without issue.

The screen shot you shared is for debugging only. Because the underline core library is done in C/C++, you need enable unmanaged debugging mode to debug in Visual Studio, but it won't prohibit your using.

kuttikrishnan commented 1 year ago

I created a solution with 3 different projects

In all the project I referenced the same SharpExt4 project library and all configured to run a target framework - x86 .

I used the same USB drive which have the EXT4 file system . I am able to read the EXT4 through my Dotnet core console and Windows App . But the MAUI is failing with an exception as mentioned below .

System.IO.IOException: 'Could not read disk MBR.'

I am debugging through VS2022 with admin privilege . In all the above mentioned 3 programs, I used the same disk number and partition number. It will be great if you are able to help to resolve this MAUI specific issue. Please let me know if you need any other information from me.

nickdu088 commented 1 year ago

Theoretically it should work with .net any application type, but I don't have experience on MAUI. You can upload your sample project.

System.IO.IOException: 'Could not read disk MBR.' comes from here: https://github.com/nickdu088/SharpExt4/blob/main/SharpExt4/ExtDisk.cpp#L76

kuttikrishnan commented 1 year ago

Please find the below-mentioned sample code. In that, there is a project named "BlazorEXT4" , which has the issue which I mentioned. The other 2 projects are working as expected.

https://stiotedgemessagesdev001.blob.core.windows.net/ext4/EXT4.zip

Please let me know your comments/guidelines on this.

kuttikrishnan commented 1 year ago

It will be very helpful if you are able to share your comments on this. Thanks and Regards, Kutti

nickdu088 commented 1 year ago

sorry, can't help. I don't know MAUI, and even can't compile the project.

kuttikrishnan commented 1 year ago

Hi Nick,

I uploaded the code to my Git repo.

https://github.com/kuttikrishnan/EXT4

It will be great if you are able to help me to resolve the issue.

My Observation When I debug the MAUI code, I observed that, it is returning from line #123 file name io_raw.cpp. Below mentioned screenshot is for your reference. But it is getting properly executed by Console and Windows App.

https://drive.google.com/file/d/1zJUZKhqskLLkXAHjeZF0_Gwe2HfvnOIl/view?usp=share_link

Please let me know your comments on this.

nickdu088 commented 1 year ago

I still can't compile your project:

Build started...
1>------ Build started: Project: KK-Test-MAUI-Blazor, Configuration: Debug x86 ------
1>C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-tizen
1>C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore
1>Done building project "KK-Test-MAUI-Blazor.csproj" -- FAILED.
1>C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-tizen
1>C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore
1>Done building project "KK-Test-MAUI-Blazor.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
========== Elapsed 00:00.639 ==========
nickdu088 commented 1 year ago

Hi Nick,

I uploaded the code to my Git repo.

https://github.com/kuttikrishnan/EXT4

It will be great if you are able to help me to resolve the issue.

My Observation When I debug the MAUI code, I observed that, it is returning from line #123 file name io_raw.cpp. Below mentioned screenshot is for your reference. But it is getting properly executed by Console and Windows App.

https://drive.google.com/file/d/1zJUZKhqskLLkXAHjeZF0_Gwe2HfvnOIl/view?usp=share_link

Please let me know your comments on this.

but from your screenshot, you didn't open the disk correctly. You may need admin permission to run this project. You can add GetLastError () to see what exactly error code and find out the reason.

kuttikrishnan commented 1 year ago

Thanks for your comments. I checked the Last error value which is return 5 (Error code 5 stands for "Access is Denied"). I have opened my VS2022 in administrator mode. I in the same solution I have my Console & Windows app, both projects are referenced the same SharpExt4 lib and those 2 projects are working fine.