StorageCredentials.cs not found - c#

I'm using WindowsAzure.Storage, in a .NET CORE 2.0 library (dll) but when I unit test I get StorageCredentials.cs not found.
public class AzureFileStorage : IDocumentStorage
{
CloudStorageAccount storageAccount;
CloudFileClient fileClient;
StorageCredentials credit;
public AzureFileStorage()
{
credit = new StorageCredentials(appSettings.Current.Settigns["azAccountName"],appSettings.Current.Settigns["keyValue"]);
storageAccount = new CloudStorageAccount(credit, true);
fileClient = storageAccount.CreateCloudFileClient();
}
}
I can navigate tot he file and the file/class is there, Am I missing something?
Also, the path starting C:\Program Files (x86)\Jenkins\ is nowhere to find on my computer.

According to your error message, I suppose the issue is related with Debug settings.
There are some ways you could have a try.
1.Open Tools>Debugging>General>tick Enable Just My Code. For more details, please refer to this article.
2.Right click "Solution >Properties and then go to "Debug Source Files". Check under "Do not look for these source files" window if you have your problematic file path written in it. For more details, please refer to this article.
Uncheck Enable source server support in Debugging/General.
4.The system has a StorageCredentials class. After I have installed WindowsAzure.Storage nuget package(like 8.7.0), I could use this class by adding using Microsoft.WindowsAzure.Storage.Auth reference;
5..Net core 2.0 compatibility.I also meet a similar error like you. Just the class is different. Above the package is an exclamation mark. It says this package version can not support .NET Standard 2.0. It supports in
version 5.2.4. You know the standard 2.0 is new, there are still some features can not support in it. You could also check your package dependencies of compatibility. If your error is this, you could to wait for core 2.0 to update to support for some packages. Or choose a compatible version of packages.

Related

Getting Conflict error for Amazon.RegionEndpoint with Sagemaker

I have created an applicataion in c#, where I need to put some data on S3 bucket, and to Invoke AWS sagemaker APIs.
Since the same Amazon.RegionEndPoint class exists in both the references, it is giving below error.
The type 'RegionEndpoint' exists in both 'AWSSDK.Core,
Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604' and
'AWSSDK, Version=2.3.55.2
Basically I am trying to upload files on AWS S3, following code I have used.
AmazonS3Client s3Client = new AmazonS3Client(_AWS_ACCESS_KEY_ID, _AWS_SECRETE_ACCESS_KEY, Amazon.RegionEndpoint.USEast2);
PutObjectRequest request = new PutObjectRequest
{
BucketName = _BucketName,
Key = i_sDestFileName,
FilePath = i_sSourceFilePath,
ContentType = "text/plain"
};
s3Client.PutObject(request);
It is working fine on a single application, but when I integrated code with Sagemaker API invokation, the conflict occurs for Amazon.RegionEndpoint.USEast2.
Don't use AWSSDK package along with AWSSDK.Core. Remove it using the package manager and add your service-specific packages, for example, AWSSDK.S3 or AWSSDK.EC2 .
AWSSDK.Core is a new one with .NET core support and with that you need to install service-specific packages, while the older AWSSDK is a single package for all services. Below is the description of the older AWSSDK package from nuget:
This is the previous version 2 generation of the AWS SDK for .NET. The new version 3 of the AWS SDK for .NET uses separate packages for each service. For example Amazon S3 is in the AWSSDK.S3 package, Amazon SQS is in AWSSDK.SQS and Amazon DynamnoDB is in AWSSDK.DynamoDBv2.
Once you remove the older one and use the specific packages, the conflict will be resolved. But, note that there may be other errors then, as the constructs have changed slightly but are obvious/simple to fix. On the positive side, you get the async versions. ;)
--
// Noticed a comment from #Gerry-coll, above, on the main question, also mentions this. Leaving a detailed answer for others who bump into this issue even now.
It looks like you have two different versions of the AWS SDK installed, one much older than the other. I'd look to SO questions like Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from? for advice on resolving the conflict.
Consider moving your region details to of config file and access it from there. https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-region-selection.html

Roslyn throws The language 'C#' is not supported

I have created a class library project and did some processing and also used Roslyn to generate code.
I use the library in a WPF GUI application as a reference.
These are the NuGet packages:
Build shows no error, however when I use the following code:
private static void GetGenerator()
{
workspace = new AdhocWorkspace();
generator = SyntaxGenerator.GetGenerator(workspace, LanguageNames.CSharp);
}
I get an exception:
"The language 'C#' is not supported."
at: Microsoft.CodeAnalysis.Host.HostWorkspaceServices.GetLanguageServices(String languageName)
at: Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetLanguageServices(String languageName)
at: Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetGenerator(Workspace workspace, String language)
According to this and this, I have to copy the CodeAnalysis files locally and add the necessary references. They are there, yet the error occurs.
Is this still a bug that wasn't fixed in the last year?
What else should I do?
Most likely it's because you don't reference Microsoft.CodeAnalysis.CSharp.Workspaces in your code, i.e. you never use a type or method in this dll, so MSBuild thinks it's not needed (see e.g. this question).
So what you could do is e.g. add the following line somewhere in your class library project:
var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions);
Then MSBuild should copy Microsoft.CodeAnalysis.CSharp.Workspaces.dll over and everything should be fine. No need to reference the NuGet packages from all the other projects.
You have to add the Microsoft.CodeAnalysis package to both the class library project AND the referencing project as well.

Install-Package : Failed to add reference to 'System.Runtime'

I'm trying to install the Autofac nuget package in my project using the command
Install-Package -Prerelease Autofac
but it fails with the error
Install-Package : Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache.
I've tried re-installing .NET Framework 4.5.2 (which is the version my project targets) but got the message ".NET Framework 4.5.2 is already installed". However, searching C:\Windows\assembly\ for System.Runtime.dll doesn't find any exact matches (although there are a few instances of System.Runtime.ni.dll, which (seem to indicate) that they are really the same assembly...).
What can I do about this?
Update: apparently I was confused about the location of the GAC. Amy enlightened me, and searching in C:\Windows\Microsoft.NET\assembly instead I do find System.Runtime.dll. Why doesn't Visual Studio?
I had the same problem.
Found the solution here: https://github.com/aspnet/WebHooks/issues/18
To fix it, I added <Reference Include="System.Runtime"/> to the .csproj
file for the project, rebuilt it and it worked.
Please make sure that it is in the Global Assembly Cache.
That is an excessively unhelpful error message. It not only doesn't describe the real problem, it also leads you drastically astray to find a workaround. An assembly reference for a .NET Framework assembly must never come from the GAC. The kind of failure modes when it does can be exceedingly nasty to diagnose. Reference assemblies must come from the C:\Program Files (x86)\Reference Assemblies directory.
Looking at the .nuspec file for the Autofac nuget package you are trying to install, it supports two distinct targets. One is for DNXCore version 4.0.10-beta-22816. Hopefully you are not using it, that project is changing rapidly.
The other is .NET Portable, profile 259. Which allows your project to target .NET 4.5.x, Store, Phone80 and Phone81. What the blunt error message is telling you is that it has trouble finding that profile. Use Windows Explorer to have a look-see, the profile is stored in the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile259 directory. It has the required System.Runtime.dll reference assembly.
Well, surely it awol, I can't guess at the underlying reason.
They did make subtle mistakes in the .nuspec file. Do consider a more stable release of Autofac, you probably don't want to be a beta tester. And don't target 4.5.2, there is no point to that. It doesn't add anything interesting and forcing your user to update his .NET install is not very reasonable.

Microsoft.ApplicationInsights.Contracts does not exist in Microsoft.ApplicationInsights

I wanted to have a go at Microsoft.ApplicationInsights telemetry. Documentation claims that TelemetryContext is supposed to be in Microsoft.ApplicationInsights.Contracts namespace, however when I grab Application Insights for Web from nuget (it gets me Microsoft.ApplicationInsights as dependency), it does not seem to have Contracts in it.
Microsoft.ApplicationInsights.Contracts nuget search gives no results.
I must be missing something obvious here.
The documentation on MSDN appears to be out of date.
In 1.1 of the Application Insights SDK (the latest, which I'm assuming you are using), has TelemetryContext in this namespace: Microsoft.ApplicationInsights.DataContracts (note DataContracts not just Contracts). I used Resharper to let it find the TelemetryContext class and it found it in this namespace in the core package (Microsoft.ApplicationInsights).
The SDK release notes do not mention anything specifically about this namespace moving however, https://azure.microsoft.com/en-us/documentation/articles/app-insights-release-notes-dotnet/.
API docs now updated. Sorry for the inconvenience, and thanks for pointing this out.

Check if full version of .net is installed?

I'm building a ExcelDNA plugin that requires the full version of .Net (4.0 or 3.5) (I'm using some parts of System.Web). Because of this, users that only have the client version are getting errors.
I like to prompt the user with an "get the latest" version popup on startup if only the client version is installed.
Is there any foolproof way to check if the full version is installed? By googling it seems many recommends checking the registry, byt this seems error prone as there are many .Net versions. In such a case what paths do I need to check to build:
bool IsFullDotNetVersion()
{
}
Would it be possible/good idea to check the existence for a feature that's only available in the full version? I.e. Is it possible to check is System.Web is present in the environment? (not included in client version of .Net right?)
As a side question: How can I easy test my application with different .net version installed on my system. Is there any .Net switcher?
Look in the GAC to see if System.Web (or whatever assembly you need) is present.
Here is some code that works on my machine.
private static const string BasePath = #"c:\windows\assembly";
public static bool HasDotNetFullversion()
{
var gacFolders = new List<string>()
{
"GAC", "GAC_32", "GAC_64", "GAC_MSIL",
"NativeImages_v2.0.50727_32", "NativeImages_v2.0.50727_64"
};
var assemblyFolders = from gacFolder in gacFolders
let path = Path.Combine(BasePath, gacFolder)
where Directory.Exists(path)
from directory in Directory.GetDirectories(path)
select directory;
var hasSystemWeb = assemblyFolders.Any(x =>
x.EndsWith("system.web", StringComparison.InvariantCultureIgnoreCase));
}
Possible duplicate. How to detect what .NET Framework versions and service packs are installed? short answer is that you need to read the registry
I would suggest that rather than try and detect which .net version the client computer has, you might just bundle the full .net installer into your installation program.
In other words, detect it at the point of install and take the appropriate actions. This is the usual way of dealing with potentially missing framework parts.

Categories

Resources