Cannot compile C# project with gRPC - c#

I'm trying to create a C# gRPC client for a server I have. I have the .proto file, the file's build action is set to ProtoBuf, I have created a C# class for wrapping around the client. Everything looks fine in the IDE, no red squiggly lines, everything is good.
My protobuf file's package name is controlpanel, and the IDE has no issues with the types being imported via using Controlpanel;, no issues with that, or the types that come from it in the IDE.
The .proto file is valid, as I have used it to create both a server and a client in Go.
However, the issue comes when I try to build it.
I get errors like
error CS0246: The type or namespace name 'Controlpanel' could not be found (are you missing a using directive or an assembly reference?)
I've checked the obj/ directory, and it appears the code is generated just fine.
I have no idea what the issue is, and I have searched the Internet for about an hour, finding nothing about the issue I'm having. To the point where my only 3 search results are in Chinese.

I ran into the same problem when using gRPC in a WPF application. There is an issue on Github: https://github.com/grpc/grpc/issues/18624
Workaround:
Move code generation with proto files to a regular class library. You can then reference the class library from the WPF app and use the generated types inside it.

Related

error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

I am trying to go through this tutorial for on making sounds with waves using C#:
https://www.codeguru.com/dotnet/making-sounds-with-waves-using-c/
The first sample code it has you run is this, which is supposed to play a .wav file:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
namespace MyApp
{
class Program
{
static Audio myAudio = new Audio();
static void Main()
{
myAudio.Play("m:\\crooner2.wav",
AudioPlayMode.WaitToComplete);
}
}
}
In my code, the filepath and name of the .wav file was replaced with a different one, but otherwise the code is identical. However, I get an error regarding the second line of code: error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Without the Microsoft.VisualBasic.Devices call working, I have no way of running even the first exercise in the tutorial, and definitely no way of further progressing in using C# for sound manipulation.
I was expecting the code to run and play the .wav file. However, I got the error message instead.
As part of debugging, I came across this post on the Microsoft website:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/visualbasic#types-in-microsoftvisualbasicdevices-namespace-not-available
I'm not sure what to make of it. It seems like it's saying it could be solved by upgrading to .Net 5 or higher, but I'm already using .Net 5. It also seems like it saying that Microsoft.VisualBasic.Devices was made obsolete with .Net Core 3.0, so I'm not sure how upgrading would make it easier to use something that was made obsolete.
It also says that certain functionality in Microsoft.VisualBasic.Devices has equivalent functionality that can be called by other means. It gives specific replacement calls for Microsoft.VisualBasic.Devices.Clock and Microsoft.VisualBasic.Devices.Ports, but nothing for Microsoft.VisualBasic.Devices.Audio, which is what I want to use in my code.
I have tried this in both Visual Studio and Visual Studio Code and get the same errors either way.
With .NET Core, you generally add references via NuGet packages. There is no NuGet package for Microsoft.VisualBasic.Forms.dll, which the documentation clearly states that type is declared in. To get that assembly reference, I believe that you need to replace this line in your project file:
<TargetFramework>net5.0</TargetFramework>
with these lines:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
After doing that, you should see Microsoft.WindowsDesktop.App.WindowsForms added under Dependencies -> Frameworks in the Solution Explorer and the relevant assembly is listed under that.
You have to use reference to "Microsoft.VisualBasic" in your project.
You have two way for do that :
1st way :
Right click on project references, select "Assemblys" => "Framework" and you can search (at top right) "basic" keyword, and select "Microsoft.VisualBasic" item.
After that you can compile your project and normally its works !
Screen for add references
2nd way :
Comment or delete "using Microsoft.VisualBasic.Devices;" instruction.
The class "Audio" should be underline to red, hover with your mouse and you have option by IDE which let you "using Microsoft.VisualBasic.Devices;".
References should be automatically added in project.
And now you can compile your project.

DLL import gone wrong? Missing class

I am trying to ressurect an older project of mine in a newer Unity3D version. This is all well and good, except for a plugin that it was using is messing up.
I am using TouchScript : https://github.com/TouchScript
I updated to the newest version and everything, but i keep getting an error saying:
Assets/Scripts/Puzzle/Gesture Usage/PickupScript.cs(149,33): error CS0246: The type or namespace name `TouchHit' could not be found. Are you missing a using directive or an assembly reference?
This script has the required Using TouchScript.Hit; line. And i opened up the DLL to make sure that the class "TouchHit" is there, and it is. However when viewed in monodevelop by going to the DLL itself, it does not show at all. It shows the other classes that are supposed to be there, but not that specific TouchHit class.
I used that class, thus the error. But i am unsure on how to proceed with fixing this. I tried all sorts of import settings but no luck.
Any ideas?
Sincerely,
Smileynator
The classes in question were marked INTERNAL at some point, and documentation did not reflect this until i started looking at the commit regarding this change in feb 2014.
https://github.com/TouchScript/TouchScript/commit/ccb1a6cb44cb444618ca613fe1f8e5b15c076cc3

I am *not* missing an assembly or reference

I'm using Visual Studio 2013, and I'm getting an error in my C# code that I can't figure out. I'm working with the Microsoft Kinect SDK, but I'll keep it general.
I downloaded the SDK, and I can get the included sample programs to build and run. But when I try to use the code in my own project, I get the
Type or namespace name 'Kinect' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference)
error.
The thing is, I'm not missing an assembly or reference. I have it added to the project's references, and the path is valid. Also, the using statements at the top of the file will autocomplete to "Kinect" for me. If I start typing using Microsoft., Kinect will appear as an autocomplete option.
What are the steps to debugging an error such as this? Could it be a 32/64 bit issue? I tried using Dependency Walker to look at the Kinect DLL, and while it throws some errors (Error: Modules with different CPU types were found.), it doesn't show any issues that I don't see with other DLLs that I'm using successfully.
What are some other potential issues that might cause a problem with DLLs not being recognized?
1 - Try going to your project settings and verify the version of the .NET framework it uses.
The best to do is to choose the same version as the external libraries.
If it's a client profile, it will very often bring that exact problem. (I'm not sure what the client profile is, but I ended up never using it...)
2 - Check if any of your references got an exclamation mark.

Recurring namespace errors, but project compiles

I've been having a recurring namespace error inside one of my projects. All the references that are having issues are inside the same project and appear to be properly namespaced. Clearing some VS cache files appears to fix the problem temporarily (AppData\Local\Microsoft\VisualStudio\12.0 and AppData\Roaming\Microsoft\VisualStudio\12.0). This isn't a show-stopper by any means; it just means I can't use intellisense or code navigation.
This is especially annoying because I have two files in the same folder referencing the same namespace, with the code content in those files namespaced identically, but VS cannot find the namespace I want in one file but it can in the other. E.g....
using System;
using ExampleNamespace.Model;
namespace ExampleNamespace.DAL{
..... code content .....
}
Is the same from one file to the other. The only difference is in one file, it cannot find ExampleNamespace.Model and all the types in the namespace are not valid.
Other things I've tried:
Resetting the target framework
Build Action on files is set to compile
Deleting cache files (as above)
Opening/closing VS
I've searched high and low for an answer, but haven't found one. My main question is why the project compiles at all if the IDE can't find a reference? Doesn't the IDE essentially pseudo-compile the code to do intellisense/syntax and bug high-lighting?

Entity Framework 4 issue

Using .NET Web API (.NET 4, EF 4) and I'm getting some strange errors when debugging and really can't figure what is going on.
Say in the DocumentRepository I have this constructor:
public DocumentRepository(DocPortalContext db)
{
this._db = db;
}
If I debug and hover over _db and drill into the items in the popup window I'm coming across the following errors:
System.Data.Entity.Infrastructure.IObjectContextAdapter.ObjectContext = 'System.Data.Entity.DbContext' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.DbContext' could be found (are you missing a using directive or an assembly reference?)
and
System.Collections.Generic.ICollection>.IsReadOnly = 'System.Collections.Generic.Dictionary' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.Generic.Dictionary
No exceptions are being caught.
If I put a break point on this line in a repository method - return _db.Documents.AsQueryable(); - and hover over Document I get the following error:
System.Linq.IQueryable.Provider = 'System.Data.Entity.Infrastructure.DbQuery' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.Infrastructure.DbQuery' could be f...
Some help would be much appreciated.
Additional information:
Drilling into _db in the following way gives message quoted at the end:
base(System.Data.Entity.DbContext) -> Internal Context -> _appConfig -> and finally Default Connection Factory has the following error beside it "The function evaluated requires all threads to run."
More information as per my comment:
This isn't really related to the question, but it has me thinking there could be something wrong with my install of .NET or VS - I don't know enough about the pipework to make that call, maybe one of you can. Anyway, I can browse to a URI in my WebAPI project and get JSON returned in the browser. When I try to consume the URI in my Website project, I get this in my browser: Could not find file 'C:\Program Files (x86)\IIS Express\System.Net.Http.StreamContent'. which is also caught as an exception.
By default EF 4 generates proxy classes on the fly that inherit from your POCO classes or your model first classes. That is most likely why you get these errors on runtime. The odd things is that all required usings should be included.
Are you sure you reference System in your POCO classes (presuming you have POCO classes)?
Do all projects in your solution have the same .NET version setup in project's properties?
Do those versions agree with the version on the MSDN describing the missing classes?
Try registering your entity-framework dll and sql-server dll in global assembly cache using gacutil.exe from visual studio command prompt
I had come across this issue recently on a small sample application where we just included nuget packages and created some data layer objects. This is what we did and it solved the issue
Make sure temp folders for .net are clean . usually in asp.net temporary files in windows directory.
Make sure your visual studio is upto date and not requiring a restart due to nuget reinstall. Not sure if it solved or did help but i checked this as well and restarted vs.
Clean the projects and made sure that dlls are present. if you are using some webmatrix dll for asp.net simple membership make sure you have selected to copy it locally. This was one issue when we were seeding data for roles and members for mvc4 simple membership use but may not be the case for your project.
We also checked that in web projects the configuration for ef corresponds to proper version of ef.
Build the solution and run it after a vs 2012 restart and it worked fine. Now I dont know exactly which of these things helped in resolving this issue but doing all 4 worked in one case.
Just thought to share if it helps.
These look like issues relating to an incompatibility between your project's target .Net version and the build version of the assembly you're referencing.
In this instance, you should make sure that the assembly you are referencing is less than or equal to your project's target .Net Framework version.
I have seen this message numerous times. 9 times out of ten, this means that there is a likely problem with the App.config file. Usually, it is just missing. In other words, for every project folder you have referencing the Entity Model you need to place a copy of that App.config file within it. If they are already there, then delete the App.config file that partners the edmx file, and recompile the Entity Model separately to regenerate it. (DON'T DELETE THE EDMX FILE or THE DESIGNER CLASS) Then you have to replace all the App.config's again. Yes, it sucks!!! Sometimes, LinqPad is great for checking this issue too. You can reference the dll file in LinqPad and attempt to run queries giving you the same error message letting you know that the problem is not just Visual Studio.
Hope this helps...Good Luck!!!!
How are you implementing your repository? Seems to me that maybe the problem is that your application is running on a different thread than your repository and that might be the answer for the "The function evaluated requires all threads to run." message.

Categories

Resources