Getting runtime version of a Silverlight assembly

后端 未结 3 1320
后悔当初
后悔当初 2020-12-30 22:18

I want to show my Silverlight 3 application\'s version number in the about box, but when I use a traditional .Net call like:

Assembly.GetExecutingAssembly().         


        
相关标签:
3条回答
  • 2020-12-30 22:52

    GetName is marked as Security Critical and hence you get an exception when you attempt to call it.

    You will need to use the FullName property and parse out the Version=x.x.x.x part of the string.

    0 讨论(0)
  • 2020-12-30 22:55
    private static Version ParseVersionNumber(Assembly assembly)
    {
        AssemblyName assemblyName = new AssemblyName(assembly.FullName);
        return assemblyName.Version;
    }
    

    or this:

    Assembly assembly = Assembly.GetExecutingAssembly(); 
    String version = assembly.FullName.Split(',')[1];
    String fullversion = version.Split('=')[1]; 
    

    From: http://betaforums.silverlight.net/forums/p/128861/288595.aspx

    a post about it:

    http://forums.silverlight.net/forums/p/93400/214554.aspx

    You can look at the js file I posted here: Detect Silverlight version required by an assembly

    Your error is expected.as it is secutiry critical, above are some work arounds.

    0 讨论(0)
  • 2020-12-30 22:59

    You can use

    Assembly.GetExecutingAssembly()
     .GetCustomAttributes(false).OfType<AssemblyVersionAttribute>()
     .Single().Version;
    
    0 讨论(0)
提交回复
热议问题