Activating license from library results in error: The invoked member is not supported in a dynamic assembly

I have a .net standard library, that we intend to use as a helper for different parts of aspose.Words across multiple applications.

In this library, we have embeded a temporary license file for Aspose Words, in order to test out the features.

The first part we wanted to test out is registering the license via the library.
This is the license registration code

public static class AsposeWordsHelper
{
public static void SetAsposeWordsLicense()
{
    // Apply Aspose.Words API License
    var license = new License();
    // Place license file in Bin/Debug/ Folder
    license.SetLicense("Aspose.Words.NET.lic");
}
}

The library is being build into a private nuget package feed, that we then use in our other applications.
The intended use is something like this to register the license:
AsposeWordsHelper.SetAsposeWordsLicense();

This seems to work correctly when we run the application locally. However when we deploy the application to a live enviorment we get the following error

System.NotSupportedException: The invoked member is not supported in a dynamic assembly.
   at System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames()
   at  .(MethodBase , Object , Object[] , Boolean )
   at  .(MethodBase , Boolean )
   at  .()
   at  .(Boolean )
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at  .(Object )
   at  . ()
   at  .(Object , UInt32 )
   at  .(Boolean )
   at  .(Object[] , Type[] , Type[] , Object[] )
   at  .(Int32 , Type[] , Type[] , Boolean )
   at  . (  ,   )
   at  .()
   at  .(Boolean )
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at  .(Object )
   at  . ()
   at  .(Object , UInt32 )
   at  .(Boolean )
   at  .(Object[] , Type[] , Type[] , Object[] )
   at Aspose.Words.License.SetLicense(String licenseName)

Any suggestions on how we can solve this problem if possible at all.
We are using Aspose.Wrods version 20.11.0

@dbc Could you please provide more information about your live environment?
From stack trace it seems the program cannot get resource from the assembly. You can try getting resource in your code and apply the license from stream. For example see the following code:

internal static class AsposeWordsHelper
{
    public static void SetAsposeWordsLicense()
    {
        // Apply Aspose.Words API License
        License license = new License();

        // Get license from resources.
        Assembly assem = Assembly.GetCallingAssembly();
        using (Stream stream = assem.GetManifestResourceStream(@"LicenseFileResourceName"))
        {
            license.SetLicense(stream);
        }
    }
}

This way you will be able to check whether the problem is in Aspose.Words or in getting embedded resource in your application in general.

I’ve tried out the sample that you suggested.
However it resulted errors as well. It appears that the stream will result in a null value.

Here is the exception and stacktrace that I get back:

System.ArgumentNullException: Value cannot be null.

Parameter name: stream
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at .(Object )
at .()
at .(Boolean )
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at .(Object )
at . ()
at .(Object , UInt32 )
at .(Boolean )
at .(Object[] , Type[] , Type[] , Object[] )
at Aspose.Words.License.SetLicense(Stream stream)
at InCom.Aspose.Helper.AsposeWordsHelper.SetAsposeWordsLicense()

@dbc Thank you for additional information. It seems resource cannot be retrieved from the assembly. Could you please create a simple application that will allow us to reproduce the problem on our side. We will check it and provide you more information. But make sure you exclude license file from the project to avoid its leakage.

I’ve done some debugging, and found out that the reason the suggested solution didn’t work was due to the way naming of the resource are handled.

The following code works for me.

public static void SetAsposeWordsLicense()
{
// Apply Aspose.Words API License
var license = new License();

        // Get license from resources.
        var assembly = Assembly.GetExecutingAssembly();
        string licenseFileResourceName = assembly.GetManifestResourceNames().FirstOrDefault(r => r.EndsWith("Aspose.Words.NET.lic"));
        
        using (Stream stream = assembly.GetManifestResourceStream(licenseFileResourceName))
        {
            license.SetLicense(stream);
        }
    }

@dbc It is good that you managed to find the solution. But if it is not difficult, could you please create a simple application that will allow us to reproduce and investigate the initial problem? This will allow us to avoid such issues in the future.