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

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.

Related

"Can't resolve reference" when using Azure Service Bus package in Xamarin.iOS

I'm using the Microsoft.Azure.ServiceBus package in my Xamarin.iOS project. This works fine for Debug builds, when linking is off, but when I want to make a Release build for distribution (with the default setting Link Framework SDKs only), it fails with the following error:
/Users/Gerwin/Public/Projects/Sandbox/Test3/MTOUCH: Error MT2101: Can't resolve the reference 'System.Threading.Tasks.Task`1<Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult> Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions::AcquireTokenAsync(Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext,System.String,System.String,Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential)', referenced from the method 'System.Void Microsoft.Azure.Services.AppAuthentication.AdalAuthenticationContext/d__0::MoveNext()' in 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. (MT2101) (Test3)
Configuration:
macOS 10.15.1
Visual Studio for Mac 8.3.8 (build 8)
Xamarin.iOS 13.6.0.12
.NET Core SDK 3.0.100
Steps to reproduce:
Create a new iOS app via the wizard
Add the NuGet package Microsoft.Azure.ServiceBus (the latest version, 4.1.1)
Add some code to call the API, e.g. in the FinishedLaunching method in AppDelegate.cs:
InvokeOnMainThread(async () => {
var client = new TopicClient("", "", RetryPolicy.NoRetry);
var message = new Message(new byte[0]);
await client.SendAsync(message);
await client.CloseAsync();
});
(you'll need a using Microsoft.Azure.ServiceBus; too)
Now, a Debug build for the Simulator works fine
However, a Release build for an iOS device produces the error mentioned above
The build output shows a slightly different but related error:
MTOUCH : error MT2101: Can't resolve the reference 'Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate', referenced from the method 'System.Void Microsoft.Azure.Services.AppAuthentication.ClientCertificateAzureServiceTokenProvider/d__8::MoveNext()' in 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Adding the NuGet package Microsoft.IdentityModel.Clients.ActiveDirectory separately doesn't help; disabling linking works, but produces much larger .IPA files. (Which is a problem in my actual app, which uses much more libraries.) I've tried to use the --linkskip option, e.g. using --linkskip=Microsoft.IdentityModel.Clients.ActiveDirectory doesn't help. I ended up using an older version (2.0.0) of the ServiceBus package.

Error: An assembly specified in the application dependencies manifest not found Package:Newtonsoft.Json when deploying .Net core 2.2

I am deploying a .Net core 2.2 console application using self contained deployment and using some 3rd party libraries like(log4net and Newtonsoft.Json). The application is working fine on the system it is developed but not working when deployed to any other system. The below error displays:
C:\Users\shubhamjain\source\repos\Collect\Collect\bin\Release\netcoreapp2.2\win-x64>Collect.exe
Error:
An assembly specified in the application dependencies manifest (Collect.deps.json) was not found:
package: 'Newtonsoft.Json', version: '12.0.2'
path: 'lib/netstandard1.3/Newtonsoft.Json.dll'
I have tried the below things:
Changing the .Net core version from 2.1 and 2.2
changing the version of Newtonsoft.Json from nuget
Updating visual studio 2019
Nothing worked but when I looked to a file ("Collect.runtimeconfig.dev.json" in path C:\Users\shubhamjain\source\repos\Collect\Collect\bin\Release\netcoreapp2.2\win-x64) and change the shubhamjain with the deployed system username, everything works fine.
Now, What I observe that Newtonsoft.Json is depends on file (.runtimeconfig.dev.json) and in order to make it work I have to change the username in this file.
Is there any way to resolve this automatically?
Collect.runtimeconfig.dev.json :
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\shubhamjain\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\shubhamjain\\.nuget\\packages",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" ]
}
}
Can you try configuring your json file with using %username% parameter. I am not sure if it is possible to run that way but you can use that parameter in the Command Prompt to get the logged in username.
You can check the link for more detail.
In this case your Collect.runtimeconfig.dev.json will be :
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\%username%\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\%username%\\.nuget\\packages",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder" ]
}
}
Also you can prepare different configuration files for different environments. Maybe this Microsoft Doc could be helpful about that.

NLog - System.MethodAccessException only in VMWare Horizon View client

I updated my C# WPF application to use latest versions of NLog and NLog.Extensions.Logging.
It works everywhere except in this VMWare Horizons client where it crashes with this error:
$exception {"Attempt by method 'NLog.Extensions.Logging.NLogLoggerProvider..ctor(NLog.Extensions.Logging.NLogProviderOptions, NLog.LogFactory)' to access method 'NLog.LogManager.get_LogFactory()' failed."} System.MethodAccessException
This project is currently using NLog v4.5.11 and
NLog.Extensions.Logging v1.4
A previous version of my application which uses NLog v.4.4.12 and
NLog.Extensions.Logging v1.0 worked in this VM so i am trying to fall back to that. Then i'll work my way up the versions of these libraries.
More to follow soon... meanwhile, any insight into what might be causing this would be very welcome.
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var loggerFactory = new LoggerFactory();
var Logger = loggerFactory.CreateLogger<Program>();
loggerFactory.AddNLog();
Logger.LogDebug($"============{Environment.NewLine}");
Console.ReadLine();
}
}
}
You have a problem with your deployment. Your application is not using NLog ver. 4.5 (But some older version).
LogFactory-property became public with this: https://github.com/NLog/NLog/pull/2316
Maybe you have old NLog registered in Windows GAC ? (Global Assembly Cache)
Maybe try writing the typeof(NLog.LogFactory).Assembly-location using Console.WriteLine.
I'll add to answer https://stackoverflow.com/a/54557849/8081796
This issue is actual for Windows 8.
Get path to used NLog.dll:
typeof(NLog.LogFactory).Assembly.Location
If the path leads somewhere in C:\Windows\Microsoft.NET\assembly\GAC_MSIL then just delete this file
Thanks Stepan.
As I recall, it is not easy to delete a file from the GAC. And from what I have learned, not a good practice because it could break another application that depended on it.
Windows installer maintains a reference count of items in GAC, increasing the count with each install, reducing with each uninstall. If the count goes to 0, the dll is also removed from the GAC.
I uninstalled the application that put Nlog in the GAC. (It was another application that I had written long ago.) Then i modified the installer for that old app, ensured that it did not put it back in the GAC and re-installed it. And everything was well again.

Mono:Could not load file or assembly 'System.Threading.Tasks.Dataflow'

We are using C# Roslyn Version 2.3.1 for opening .csproj projects programmatically.
For this purpose, we are using the following standard API code provided by Roslyn for opening the .csproj and navigating through each Microsoft.CodeAnalysis.Document to get the syntax tree of the Document:
public void BrowsProjectDocuments(string projectPath)
{
var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += WorkSpaceFailed;
Project currentProject = workspace.OpenProjectAsync(projectPath).Result;
foreach(Document document in currentProject.Documents)
{
Task<SyntaxTree> documentSyntaxTree = document.GetSyntaxTreeAsync();
.....
.....
}
}
private static void WorkSpaceFailed(object sender, WorkspaceDiagnosticEventArgs e)
{
Console.WriteLine(e.Diagnostic.Message);
}
When we run the above code on Windows 7 using .NET Framework 4.6.1/4.6.2 and Roslyn 2.3.1, the code runs well and we get the required syntax tree of each Document.
But when we try to run the same code on Ubuntu 16.04, currentProject.Documents returns 0 count and we get following error thrown in the WorkSpaceFailed event hooked up:
Msbuild failed when processing the file
'/home/user/CSharp/RoslynSamples/AplModel/AplModel.csproj'
with message:
Could not load type of field
'Microsoft.Build.BackEnd.Logging.LoggingService:_loggingQueue' (20)
due to: Could not load file or assembly
'System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
assembly:System.Threading.Tasks.Dataflow, Version=4.5.24.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type: member:
We have installed mono on the Ubuntu machine using:
sudo apt-get install mono-complete
What are we missing?
Look a workaround here: https://github.com/Microsoft/msbuild/issues/1469
You need to use a Mono hosted MSBuild (for example, taken from Mono or built under Mono), install System.Threading.Tasks.Dataflow and Microsoft.VisualStudio.RemoteControl packages from NuGet.
The MSBuildWorkspace is not currently cross platform. It only works on .net desktop clr. But my knowledge of mono is not so good, so it may be possible to get it to work on mono. Your error message tells me that you need to include the DataFlow library somehow.

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

Categories