Hello I am using GroupDocs.Total.lic
in my application and currently using the below
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseViewer(stream);
}
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseConversion(stream);
}
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseAnnotation(stream);
}
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseMerger(stream);
}
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseWatermark(stream);
}
Now I am planning to use Groupdocs.Search in my application and hence added the below code
using (Stream stream = appAssembly.GetManifestResourceStream(resourceName))
{
GD.Utilities.ApplyLicenseSearch(stream);
}
but I am getting the error → License not Valid
groupdocs.search error.png (15.8 KB)
my full code is below
#region ProductLicense
/// <summary>
/// Set product's license
/// </summary>
public static void ApplyLicense(string filepath)
{
GroupDocs.Viewer.License lic1 = new GroupDocs.Viewer.License();
lic1.SetLicense(filepath);
//GroupDocs.Parser.License lic2 = new GroupDocs.Parser.License();
//lic2.SetLicense(filepath);
}
/// <summary>
/// Set product's license for Viewer
/// </summary>
public static void ApplyLicenseViewer(Stream stream)
{
GroupDocs.Viewer.License lic = new GroupDocs.Viewer.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for Parser
/// </summary>
public static void ApplyLicenseParser(Stream stream)
{
GroupDocs.Parser.License lic = new GroupDocs.Parser.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for ApplyLicenseWatermark
/// </summary>
public static void ApplyLicenseWatermark(Stream stream)
{
GroupDocs.Watermark.License lic = new GroupDocs.Watermark.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for Conversion
/// </summary>
public static void ApplyLicenseConversion(Stream stream)
{
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for Annotation
/// </summary>
public static void ApplyLicenseAnnotation(Stream stream)
{
GroupDocs.Annotation.License lic = new GroupDocs.Annotation.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for Annotation
/// </summary>
public static void ApplyLicenseMerger(Stream stream)
{
GroupDocs.Merger.License lic = new GroupDocs.Merger.License();
lic.SetLicense(stream);
}
/// <summary>
/// Set product's license for Annotation
/// </summary>
public static void ApplyLicenseSearch(Stream stream)
{
GroupDocs.Search.License lic = new GroupDocs.Search.License();
lic.SetLicense(stream);
}
#endregion
below →
string viewerAssemblyName = "GroupDocs.Viewer.dll";
string signatureAssemblyName = "GroupDocs.Signature.dll";
string annotationAssemblyName = "GroupDocs.Annotation.dll";
string comparisonAssemblyName = "GroupDocs.Comparison.dll";
string conversionAssemblyName = "GroupDocs.Conversion.dll";
string searchAssemblyName = "GroupDocs.Search.dll";
// set GroupDocs.Viewer license
DomainGenerator viewerDomainGenerator = new DomainGenerator(viewerAssemblyName, "GroupDocs.Viewer.License");
viewerDomainGenerator.SetViewerLicense();
// set GroupDocs.Annotation license
DomainGenerator annotationDomainGenerator = new DomainGenerator(annotationAssemblyName, "GroupDocs.Annotation.License");
annotationDomainGenerator.SetAnnotationLicense();
// set GroupDocs.Conversion license
DomainGenerator conversionDomainGenerator = new DomainGenerator(conversionAssemblyName, "GroupDocs.Conversion.License");
conversionDomainGenerator.SetConversionLicense();
// set GroupDocs.Comparison license
DomainGenerator comparisonDomainGenerator = new DomainGenerator(comparisonAssemblyName, "GroupDocs.Comparison.Common.License.License");
comparisonDomainGenerator.SetComparisonLicense();
// set GroupDocs.Signature license
DomainGenerator signatureDomainGenerator = new DomainGenerator(signatureAssemblyName, "GroupDocs.Signature.License");
signatureDomainGenerator.SetSignatureLicense();
// set GroupDocs.Search license
DomainGenerator searchDomainGenerator = new DomainGenerator(searchAssemblyName, "GroupDocs.Search.License");
searchDomainGenerator.SetSearchLicense();
public class DomainGenerator
{
private readonly Type CurrentType;
/// <summary>
/// Constructor
/// </summary>
public DomainGenerator(string assemblyName, string className)
{
// Get assembly path
string assemblyPath = GetAssemblyPath(assemblyName);
// Initiate GroupDocs license class
CurrentType = CreateDomain(assemblyName + "Domain", assemblyPath, className);
}
/// <summary>
/// Get assembly full path by its name
/// </summary>
/// <param name="assemblyName">string</param>
/// <returns></returns>
private string GetAssemblyPath(string assemblyName)
{
// Get path of the executable
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string uriPath = Uri.UnescapeDataString(uri.Path);
// Get path of the assembly
string path = Path.Combine(Path.GetDirectoryName(uriPath), assemblyName);
return path;
}
/// <summary>
/// Create AppDomain for the assembly
/// </summary>
/// <param name="domainName">string</param>
/// <param name="assemblyPath">string</param>
/// <param name="className">string</param>
/// <returns></returns>
private Type CreateDomain(string domainName, string assemblyPath, string className)
{
// Create domain
AppDomain dom = AppDomain.CreateDomain(domainName);
AssemblyName assemblyName = new AssemblyName { CodeBase = assemblyPath };
// Load assembly into the domain
Assembly assembly = dom.Load(assemblyName);
// Initiate class from the loaded assembly
Type type = assembly.GetType(className);
return type;
}
/// <summary>
/// Set GroupDocs.Viewer license
/// </summary>
/// <param name="type">Type</param>
public void SetViewerLicense()
{
SetLicense((GroupDocs.Viewer.License)Activator.CreateInstance(CurrentType));
}
/// <summary>
/// Set GroupDocs.Annotation license
/// </summary>
/// <param name="type">Type</param>
public void SetAnnotationLicense()
{
SetLicense((GroupDocs.Annotation.License)Activator.CreateInstance(CurrentType));
}
/// <summary>
/// Set GroupDocs.Comparison license
/// </summary>
/// <param name="type">Type</param>
public void SetComparisonLicense()
{
SetLicense((GroupDocs.Comparison.License)Activator.CreateInstance(CurrentType));
}
/// <summary>
/// Set GroupDocs.Conversion license
/// </summary>
/// <param name="type">Type</param>
public void SetConversionLicense()
{
SetLicense((GroupDocs.Conversion.License)Activator.CreateInstance(CurrentType));
}
/// <summary>
/// Set GroupDocs.Signature license
/// </summary>
/// <param name="type">Type</param>
public void SetSignatureLicense()
{
SetLicense((GroupDocs.Signature.License)Activator.CreateInstance(CurrentType));
}
/// <summary>
/// Set GroupDocs.Search license
/// </summary>
/// <param name="type">Type</param>
public void SetSearchLicense()
{
SetLicense((GroupDocs.Search.License)Activator.CreateInstance(CurrentType));
}
private void SetLicense(dynamic obj)
{
Assembly appAssembly = Assembly.GetExecutingAssembly();
using (Stream stream = appAssembly.GetManifestResourceStream("DocPro.DMS.WebApp.GroupDocs.Total.lic"))
{
obj.SetLicense(stream);
}
}
}
I don’t know What I am doing wrong here