dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

FileNotFoundException when I try to get the version of the assembly #15679

Closed ComptonAlvaro closed 1 year ago

ComptonAlvaro commented 1 year ago

Description

At runtime, I would like to know the version of the assembly, for that, I am using this code:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
string miStrVersionEnsamblado = fvi.FileVersion;

it works when I debug the application, but when I publish it to create the apk and I install it, I get this exception:

Android.runtime.javaProxyThrowable:Syste.IO.FileNotFoundException:/MyApplication.dll at System.Diagnostics.FilveVersionInfo.GetVersionInfo(string)

The message is clear. It seems it is not possible to find the .dll. Perhaps when the application is published, there is not a .dll from which to get the version.

So I would like to know how could I know the version of the application at runtime.

Thanks.

Steps to Reproduce

  1. Create a MAUI application
  2. In the event of the button, add the 3 lines of code that I tell above.
  3. Publish the application
  4. Run the application
  5. Click the buttton.

Link to public reproduction project repository

It is not needed

Version with bug

7.0.49

Last version that worked well

7.0.86

Affected platforms

Android

Affected platform versions

Android API 31

Did you find any workaround?

I have not found any workaround.

Relevant log output

No response

Eilon commented 1 year ago

Hi @ComptonAlvaro , I think the best way to do stuff with app versions in .NET MAUI is using the .NET MAUI Essentials Version Tracking features: https://learn.microsoft.com/dotnet/maui/platform-integration/appmodel/version-tracking. It has many useful features for checking various conditions, but it also has a VersionTracking.Default.CurrentVersion API that looks like it might be what you need here.

ComptonAlvaro commented 1 year ago

@Eilon Thanks so much. This works perfectly and it is easier than they way I was trying.

Thanks so much.