ServiceStack license error after packaging - c#

In my ServiceStack client application, everything was fine until I have tried packaging it with SmartAssembly or ILRepack. There are three DLLs:
(ServiceStack.Client.dll, ServiceStack.Interfaces.dll, ServiceStack.Text.dll)
Which when packed cause my application to crash, no matter whether I use encryption\obfuscation options or just pack them into one EXE. My app is targeting .NET 4.0 (I want to support win XP). Stack trace of the exception is:
ServiceStack.LicenseException: Unauthorized access request of a licensed feature. Type: 'AccessToken', Assembly: 'ClientTester.exe', 'My EXE path'
ServiceStack.Net40PclExport.VerifyInAssembly(Type accessType, ICollection`1 assemblyNames)
ServiceStack.LicenseUtils.RequestAccess(Object accessToken, LicenseFeature srcFeature, LicenseFeature requestedAccess)
ServiceStack.JsonServiceClient.ToJson[T](T o)
ServiceStack.EncryptedServiceClient.CreateEncryptedMessage(Object request, String operationName, Byte[] cryptKey, Byte[] authKey, Byte[] iv, String verb)
ServiceStack.EncryptedServiceClient.Send[TResponse](String httpMethod, Object request)
I can't install the patch as the installer says that it is blocked or the conditions are invalid. In addition, I am not sure that this patch would help me. Any ideas are welcome.
Sidenote: another ServiceStack application, which uses other ServiceStack DLLs except aforementioned ones works well even when packed.

It looks like the absence of an explicitly installed .NET Framework 4.0 is causing that issue. If I compile the solution for 4.5\4.6 version and pack it - everything is fine. Also compiling and packing it for .NET 4.0 and using it on PC that EXPLICITLY has this version installed works as well

Related

EnsureLibraryPresent error in huysentruitw's SapNwRfc connector with .net5

I'd like to use huysentruitw's SapNwRfc connector to connect to SAP. I have copied all the necessary files to project root (sapnwrfc.dll, icuuc50.dll, icuin50.dll, icudt50.dll) but I still got error when I try to call this:
SapLibrary.EnsureLibraryPresent();
the error I got:
System.BadImageFormatException
HResult=0x8007000B
Message=An attempt was made to load a program with an incorrect format. (0x8007000B)
Source=SapNwRfcDotNet
StackTrace:
at SapNwRfc.Internal.Interop.RfcInterop.RfcGetVersion(UInt32& majorVersion, UInt32& minorVersion, UInt32& patchLevel)
at SapNwRfc.Internal.Interop.RfcInterop.GetVersion(UInt32& majorVersion, UInt32& minorVersion, UInt32& patchLevel)
at SapNwRfc.SapLibrary.GetVersion()
at SapNwRfc.SapLibrary.EnsureLibraryPresent()
I have tried to changed platform from any CPU to x86 (then I got error from IIS Express), and x64 (the same behavior as any CPU)
Do you have any tips how to handle it?
Thank you.
EDIT
Tested with .NET Framework 4.7.2 and works fine. With Core 2.1, 3.1 and .NET5 does not work.
I have also tried it without copying the files into project folder and result is the same (files are present in System32 and SysWOW64 folders)

Could not load file or assembly System.Fabric with Azure Functions

Are there any restrictions with packages you can use with Azure Functions. I have researched as much as I can and it doesn't seem so, however when I try creating an Azure Function that references the package "Microsoft.ServiceFabric" I get the following error:
System.Private.CoreLib: Exception while executing function:
ScaleDownServiceFabrics. FunctionApp2: Could not load file or assembly
'System.Fabric, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific
file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib:
Could not load file or assembly 'System.Fabric, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
I have tried both Azure Func and.1 and 2, and .Net Framework and .Net Core with no luck.
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Fabric;
namespace FunctionApp5
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("*/5 * * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
FabricClient client = new FabricClient();
}
}
}
Is this possible, or a limitation of Azure Functions in Visual Studio - if so, what packages are acceptable?
ServiceFabric packages are x64 bit, if your function target 32bit it will fail. Try the solution proposed by Jerry Liu
Service Fabric Packages have to be added as packages instead of reference the dll directly in the project, because of the dependencies on other libraries. You should add the NuGet package Microsoft.ServiceFabric.
Microsoft.ServiceFabric latest version 6.3.x targets .Net Standard 2.0 and .Net Framework from 4.5 to 4.7.1, make sure you are using any of these on your project.
Make sure the Microsoft.ServiceFabric DLLs are being copied to the bin folder when built\deployed.
When you use FabricClient outside the cluster, you have to specify the settings and credentials, otherwise you won't be able to connect to the cluster. See this example and this docs.
FabricClient uses Service Fabric API to interact with the cluster, if are having issues with the packages, another option is use HttpClient and make the requests to the API and avoid the packages conflicts
Diego and Suraj have pointed out the cause, conflict between 64 and 32 bit.
Two points to fix
Set build platform to x64 like what you have done.
Get x64 Function runtime. Functions work on Function runtime(contained in Azure Function core tools), but the default bit is x86 downloaded by VS.
To get x64 bit in an easy way, let's use Nodejs to install Azure Functions Core Tools from NPM.
After installation, in cmd input npm i -g azure-functions-core-tools --unsafe-perm true to get Function core tools.
Then set project debug properties(right click on your project>Properties>Debug blade).
Set Launch type to Executable
Set Executable path to %appdata%\npm\node_modules\azure-functions-core-tools\bin\func.exe.
Add Application arguments start.
I run into exactly same issue as #tank140 commented in original post:
Unable to load DLL 'FabricClient.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
More details in another question that I fired on the issue. As answer, it was confirmed that SF Client API for .NET requires that SF runtime is installed on the platform, which is not supported in Azure Functions.
In my case I just update the azure platform configuration to 64 bit. However, I was using .net core 3.1 function app into win platform.

Access Denied VS 2010

i m trying to build COM dll file using C# and VS2010 - framework 3.5-:
if i try building the project without performing Clean, it will build, however this works only before any cleaning operation, after cleaning the project i will get stuck with this error
Error 16 Cannot register assembly "C:\Users\User\Desktop\Demo[Demo]
SCPP T1\bin\Debug\PrinterPlugin.dll" - access denied. Please make sure
you're running the application as administrator. Access to the
registry key
'HKEY_CLASSES_ROOT\CLSID{B9162A23-45F9-47CC-80F5-FE0FE9B9E1A2}' is
denied. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 3912 5 PrinterPlugin
i have based the original files on FrameWork 4.0 then converted to 3.5 due to COM registration incompatibility. building with Framework 4.0 will build successfully but will produce "TYPELIB" file is missing while registering the library.
further elaboration, the old PrinterPlugin works like a charm based on framework 3.5, it would register correctly, and would function with no warnings or erros of what-so-ever, these errors started popping after adding some components from another SDK that have been distributed using framework 4.0 and uses other microsoft libraries, like bidispl.dll, ReachFramework... etc.
EDIT0
i already have tried starting the VS2010 as admin, from every location.
EDIT1
i have tried building a new project using Framework 3.5, and still facing the same error, even when executing the devenv.exe as admin from the Common7 > IDE folder.
Error 18 Cannot register assembly
"C:\Users\Ameer\Desktop\projects\PrinterPlugin without resize
17-05-2015\printerplugin without resize
10-05-2015\bin\Debug\PrinterPlugin.dll" - access denied.
Please make sure you're running the application as administrator.
Access to the registry key
'HKEY_CLASSES_ROOT\CLSID{B9162A23-45F9-47CC-80F5-FE0FE9B9E1A2}' is
denied. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 3912 5 PrinterPlugin
i m guessing this is something has to do with the compatibility between the two SDKs.

TuesPechkin unable to load DLL 'wkhtmltox.dll'

I've been using TuesPechkin for some time now and today I went to update the nuget package to the new version 2.0.0+ and noticed that Factory.Create() no longer resolved, so I went to read on the GitHub the changes made and noticed it now expects the path to the dll?
IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new StaticDeployment(DLL_FOLDER_PATH)));
For the past few hours I've tried almost all the paths I can think of, "\bin", "\app_data", "\app_start", etc and I can't seem to find or figure out what it wants for the path and what dll?
I can see the TuesPechkin dll in my bin folder and it was the first path I tried, but I got the following error:
Additional information: Unable to load DLL 'wkhtmltox.dll': The
specified module could not be found. (Exception from HRESULT:
0x8007007E)
Where is that dll and now can I get it as the library doesn't seem to contain it, I tried installing the TuesPechkin.Wkhtmltox.Win32 package but the dll still is nowhere to be found. Also I am using this in a asp.net website project so I assume that using the following should work for obtaining the path, right?
var path = HttpContext.Current.Server.MapPath(#"~\bin\TuesPechkin.dll");
Further information: https://github.com/tuespetre/TuesPechkin/issues/57
The Tuespechkin has a zip file as a resource in the Win32 and Win64 embedded packages for the 'wkhtmltox.dll' file.
What it does when you use the Win32 or Win64 Embedded package is unzips the file and places it in the directory that you specify.
I have been putting a copy of the wkhtmltox dll at the root portion of my web app directory and pointing the DLL_FOLDER_PATH to it using the server physical path of my web app to get to it.
According to the author, you must set the converter in a static field for best results.
I do that, but set the converter to null when I am finished using it, and that seems to work.
Tuespechkin is wrapper for the wmkhtmlox dll file.
The original file is written in C++ and so will not automatically be usable in C# or VB.NET or any of the other managed code domains.
The Tuespechkin.dll file DOES NOT contain a copy of 'wkhtmltox.dll'. You either have to use one of the other embedded deployment modules or install a copy of the 'wkhtmltox.dll' in your web app after downloading it from the internet. That is what I do, and it seems to work just fine.
I am using Team Foundation Server, and attempts to compile code after using the Tuespechkin routines will fail the first time because the 'wkhtmltox.dll' file gets locked, but all you have to do is simply retry your build and it will go through.
I had issues with the 32-bit routine not working in a 64-bit environment and the 64-bit environment not being testable on localhost. I went with the workaround I came up with after examining the source code for Tuespechkin and the Win32 and Win64 embedded deployment packages.
It works well as long as you specify a url for the input rather than raw html.
The older package didn't render css very well.
If you are using a print.aspx routine, you can create the url for it as an offset from your main url.
I don't have the source code I am using with me at this point to offset to your base url for your web application, but it is simply an offshoot of HttpRequest.
You have to use the physical path to find the .dll, but you can use a web path for the print routine.
I hope this answers your question a bit.
If you are getting this error -> Could not load file or assembly 'TuesPechkin.Wkhtmltox.Win64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
In Visual Studio Go to -
Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64 bit version of IIS Express for web sites and projects.
I installed TuesPechkin.Wkhtmltox.Win64 Nuget package and used the following code in a singleton:
public class PechkinPDFConvertor : IPDFConvertor
{
IConverter converter =
new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
new Win64EmbeddedDeployment(
new TempFolderDeployment())));
public byte[] Convert(string html)
{
// return PechkinSync.Convert(new GlobalConfig(), html);
return converter.Convert(new HtmlToPdfDocument(html));
}
}
The web application then has to be run in x64 otherwise you will get an error about trying to load an x64 assembly in an x86 environment. Presumably you have to choose x64 or x86 at design time and use the corresponding nuget package, it would be nicer to choose this in the web.config.
EDIT: The above code failed on one server with the exact same message as yours - it was due to having not installed VC++ 2013. So the new code is running x86 as follows
try
{
string path = Path.Combine(Path.GetTempPath(), "MyApp_PDF_32");
Converter = new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
new Win32EmbeddedDeployment(
new StaticDeployment(path))));
}
catch (Exception e)
{
if (e.Message.StartsWith("Unable to load DLL 'wkhtmltox.dll'"))
{
throw new InvalidOperationException(
"Ensure the prerequisite C++ 2013 Redistributable is installed", e);
}
else
throw;
}
If you do not want run the installer for wkhtmltox just to get the dll, you can do the following:
As #Timothy suggests, if you use the embedded version of wkhtmltox.dll from TuesPechkin, it will unzip it and place it in a temp directory. I copied this dll and referenced it with the StaticDeployment option without any issues.
To find the exact location, I just used Process Monitor (procmon.exe). For me it was C:\Windows\Temp\-169958574\8\0.12.2.1\wkhtmltox.dll
In my case, I am deploying on a 64-bit VPS then I got this error. I have solved the problem by installing the wkhtmltopdf that I downloaded from http://wkhtmltopdf.org/downloads.html. I chose the 32-bit installer.
In my case, I have solved the problem by installing the Wkhtmltox for win32 at https://www.nuget.org/packages/TuesPechkin.Wkhtmltox.Win32/
This error: Unable to load DLL 'wkhtmltox.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) is returned in two situations:
1- Deploy dependency not installed:
For solve this, you can install nuget package "TuesPechkin.Wkhtmltox.Win64" and use this code (for WebApplications running in IIS):
IConverter converter =
new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
new Win64EmbeddedDeployment(
new TempFolderDeployment())));
// Keep the converter somewhere static, or as a singleton instance!
// Do NOT run the above code more than once in the application lifecycle!
byte[] result = converter.Convert(document);
In runtime this code will copy the dependency "wkhtmltox.dll" in a temporary directory like: "C:\Windows\Temp\1402166677\8\0.12.2.1". It's possible to get the destination of file using:
var deployment = new Win64EmbeddedDeployment(new TempFolderDeployment());
Console.WriteLine(deployment.Path);
2- Microsoft Visual C++ 2013 Redistributable not installed:
As described here:
https://github.com/tuespetre/TuesPechkin/issues/65#issuecomment-71266114, the Visual C++ 2013 Runtime is required.
The solution from README is:
You must have Visual C++ 2013 runtime installed to use these packages. Otherwise, you will need to download the MingW build of wkhtmltopdf and its dependencies from their website and use that with the library. https://github.com/tuespetre/TuesPechkin#wkhtmltoxdll
or, you can install the Microsoft Visual C++ 2013 Redistributable:
choco install msvisualcplusplus2013-redist
Here is AnyCpu version, also support iis-base or winform application
using TuesPechkin.Wkhtmltox.AnyCPU;
...
var converter = PDFHelper.Factory.GetConverter();
var result = converter.Convert(This.Document);
Reference : https://github.com/tloy1966/TuesPechkin
Installing the Visual C++ Redistributable for Visual Studio 2013 resolved the error for me.
https://www.microsoft.com/en-us/download/details.aspx?id=40784

TypeLoadException from log4net LogManager.GetLogger

I'm attempting to use log4net to provide logging in a Windows CE/Windows Embedded project. However, when debugging the project I get the following exception
System.TypeLoadException occurred
Message="TypeLoadException"
StackTrace:
at log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name)
at log4net.LogManager.GetLogger(Type type)
at Sis.SiLogCE.Broker.StartBroker..cctor()
at Sis.SiLogCE.Broker.EntryPoint.Program.Main()
from the following line:
private static readonly ILog log = LogManager.GetLogger(typeof(StartBroker));
At first, I thought I might have been using the wrong dll/an old dll so I downloaded the most recent version - I am using the log4net.dll from 1.2.12-bin-newkey and found in .net-cp 3.5.
I've looked though other examples and though the documentation and I can see no reason why I'm getting a type load exception here. I'm now pretty much out of ideas as to what couple be causing the exception.
Background information:
Application is to be deployed on Windows CE 6 and Windows Embedded/Windows Mobile 6 and 6/5 devices.
.net 3.5
.netcf
The following block shows loading the config for log4net from an XML file named "log4net.config".
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().
GetModules()[0].FullyQualifiedName) + "log4net.config";
if (File.Exists(path))
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
}
EDITS:
Up until now, I've only tested on Wince 6.0 so I've just had a shot with Windows Mobile 6.5 - it's no different, the same exception is presented.
Are you using the binary release, or have you built from source ? I ask as this page mentions that Compact Framework 1.0 & 2.0 are not supported by the binary release, but are supported if built from the source release.

Categories