I'm fairly new to C# and unity, and i've been trying to set up the Photon Networking service. I've run into an issue i can't figure out the cause of. Here are the two error messages.
Assets\PhotonUnityNetworking\Resources\TestConnect.cs(21,41): error CS0246: The Type or namespace name 'DisconnectCause' could not be found (are you missing a using directive or an assembly reference?)
Asseta\PhotonUnityNetworking\Resources\TestConnect.cs(21,26): error CS0115 'TestConnect.OnDisconnected(DisconnectCause)': no suitable method found to override.
However, in visual studio, nothing shows up as incorrect.
Any help as to the cause of these issues appreciated.
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestConect : MonoBehaviourPunCallbacks
{
private void Start()
{
print("Connecting to server...");
PhotonNetwork.GameVersion = "0.0.1";
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
print("Connected to server!");
}
public override void OnDisconnected(DiconnectionCause cause)
{
print("Disconnected from Server for reason " + cause.ToString());
}
}
First another important note: You should not put any of your custom scripts inside a folder called Resources!
Also afaik PhotonUnityNetworking is their official folder of Photon itself. I'ld recommend to not modify or add anything within it, makes it hard to upgrade or fix it later if you have messed it up somehow.
Then to your issue
It is as the error already suggests
are you missing a using directive
DisconnectCause belongs to another namespace Photon.Realtime.
You will need to add a
using Photon.Realtime;
on the top of that file or have to address it directly like
public override void OnDisconnected(Photon.Realtime.DisconnectCause cause)
{
...
}
Strange though that VisualStudio doesn't note that...
The second error is just a follow-up compile error not finding the according method to override because of a supposed signature mismatch since it doesn't know the type you used as parameter due to the error before.
In the future please don't post screenshots of code and error messages! This makes it not only harder to solve the issue but also makes it impossible for others to find this thread when searching for the error message content in order to see if it was already solved somewhere!
Rather copy & paste the raw text I your question and format it as code using the { } button.
Related
I'm trying to compile a project I'm working on and this error mesages pops out:
Invalidating makefile for SpaceShooterEditor (SpaceShooter.Build.cs modified)
While compiling E:\ue projects\SpaceShooter\Intermediate\Build\BuildRules\SpaceShooterModuleRules.dll:
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(3,29) : error CS0246: The type or namespace name 'ModuleRules' could not be found (are you missing a using directive or an assembly reference?)
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(5,25) : error CS0246: The type or namespace name 'ReadOnlyTargetRules' could not be found (are you missing a using directive or an assembly reference?)
ERROR: Unable to compile source files.
Any idea why this might happen? Last night i was trying to code a widget, modified the build.cs, then replaced the modified version (which chrashed the game) with a build.cs that worked previously, and still nothing? Is there any hope to make it work or should i start over? Moreover, how can this be avoided?
I already did the restarts and refreshes. I went to even delete the binaries and some cashed files and it didn't work.
Below you'll find the content of the Build.cs:
public class SpaceShooter : ModuleRules
{
public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
When i try to input specify the using UnrealBuildTool;, Visual Studio, for some reason, deletes it when i hit compile or save.
After some digging, i found out that wrapping the content in a namespace UnrealBuidTool.Rules{} solves this. In the end, the build file looks like this:
namespace UnrealBuildTool.Rules
{
public class SpaceShooter : ModuleRules
{
public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
}
As you do not share what is included in your Build.cs file I will just explain what the error is and how you could fix it. The error basically says that it couldn't compile the Build.cs file based on the lines 29 and 25, and that the types that are used there called 'ModuleRules' and 'ReadOnlyTargetRules' could not be found in any of the namespaces that were included by the using statements at the top of Build.cs. These types are both stored in the UnrealBuildTool namespace and can thus be included in your file by typing:
using UnrealBuildTool;
This however seems like a trivial solution to your problem, but as you do not share a lot of info this is the best solution I can give you for now.
I'm fairly new to .NET and I'm trying to get an old program to work that no longer has it's .csproj file. I've managed to receive an old .sln file from the creator and opened the solution in VS.
From what I can see this is a Developer Web Server project?
Here is the issue.
In the folder Smreka there are 2 files, log.cs and smreka.cs. The log.cs contains the implementation of a class Logger, which I am trying to import in to smreka.cs. They are both using the same namespace Bum.Iglavci.Smreka so as far as I know, I should be able to import the Logger class without any issues.
The problem is that the compiler just can't see it. If I try to directly import it with using static Bum.Iglavci.Smreka.Logger;, I get an error Feature 'using static' is not available in C# 5. Please use language version 6 or greater.
I would like to know why the namespace can't see each other. Is it because I'm missing the .csproj file? Does Developer Web Server even need a .csproj file? If so what's the best way to generate one?
EDIT:
Due to some confusion I'll try to add more details regarding how log.cs and smreka.cs look like. The files are actually a lot longer but I think this should give an idea.
log.cs:
namespace Bum.Iglavci.Smreka{
public class Logger{
public Logger(){
}
public void DoSomething(){}
}
}
smreka.cs:
namespace Bum.Iglavci.Smreka{
public class Baza{
private Logger log;
public Baza(){
log = new Logger();
}
}
}
The compiler has no idea what Logger is under property private Logger log; It states the error The type or namespace name 'Logger' could not be found (are you missing a using directive or an assembly reference?)
I think the namespace is correctly placed, that's why i have a feeling there's something wrong with the project or the solution itself that i need to fix.
Since both classes are in the same namespace they are already able to use each other. You can acces the class by simply doing the following. Let's take Log as the class to call the other class.
Log class:
namespace Bum.Iglavci
{
public class Log
{
public static void ExecuteDoSomething()
{
Smreka.DoSomething();
}
}
}
Smerka class:
namespace Bum.Iglavci
{
public class Smerka
{
public static void DoSomething()
{
//execute code here
}
}
}
It could be possible that the files have the Buil Action property set to
None this will not compile the files. Set it to C# Compiler, this should solve it.
If you don't know how to acces the properties of a file.
Right click the file
Navigate to Properties in the bottom of the list
Set the Build Action to C# compiler (see image)
I found no simple solution. I now created a new .net framework application project and added the files in to the new project. For some reason the namespace works correctly now and the files can see each other in the same namespace.
Yes the error comes from the fact that you don't have a .csproj file.
Such files contain the list of files to compile when building a project. Just having the solution file is not enough.
I suggest some readings on project and solution using Visual Studio :
https://learn.microsoft.com/en-us/visualstudio/ide/solutions-and-projects-in-visual-studio?view=vs-2022
https://learn.microsoft.com/en-us/visualstudio/get-started/tutorial-projects-solutions?view=vs-2022
Needing to support CMS-user uploaded SVG images in Episerver 10.10.5.0. It was a schlep, but I was able to come right using Marija's solution (in which she documents several others having these issues...).
My difficulty now is with implementing the second bit of Marija's solution, in which thumbnails are made available (rather than default icons) for the SVG images and in which the SVG images render properly in the editor:
[ServiceConfiguration(typeof(IModelTransform), Lifecycle = ServiceInstanceScope.Singleton)]
public class ThumbnailModelTransform : StructureStoreModelTransform
{
public ThumbnailModelTransform(
IContentProviderManager contentProviderManager,
ILanguageBranchRepository languageBranchRepository,
IContentLanguageSettingsHandler contentLanguageSettingsHandler,
ISiteDefinitionRepository siteDefinitionRepository,
IEnumerable hasChildrenEvaluators,
LanguageResolver languageResolver, UrlResolver urlResolver, TemplateResolver templateResolver) :
base(
contentProviderManager,
languageBranchRepository,
contentLanguageSettingsHandler, siteDefinitionRepository,
hasChildrenEvaluators,
languageResolver,
urlResolver,
templateResolver)
{
}
public override void TransformInstance(IContent source, StructureStoreContentDataModel target, IModelTransformContext context)
{
base.TransformInstance(source, target, context);
var contentWithThumbnail = source as VectorFile;
if (contentWithThumbnail != null)
{
var urlResolver = ServiceLocator.Current.GetInstance();
var defaultUrl = urlResolver.GetUrl(contentWithThumbnail.ContentLink, null, new VirtualPathArguments { ContextMode = ContextMode.Default });
target.ThumbnailUrl = defaultUrl;
}
}
}
I get the dreaded error CS0246 for most of the terms in Marija's code (one example below):
The type or namespace name 'StructureStoreModelTransform' could not be found (are you missing a using directive or an assembly reference?)
Here are the terms for which I receive that error (or a similar one):
StructureStoreModelTransform
ServiceConfiguration
IModelTransform
Lifecycle
StructureStoreContentDataModel
IModelTransformContext
ISiteDefinitionRepository
IEnumerable
LanguageResolver
UrlResolver
TemplateResolver
I've tried adding a bunch of directives: (or dependencies? what are these called?)
using System.Collections.Generic;
using System.Linq;
using System.Web;
...and a laundry list of others that didn't work, which I won't include here.
My colleague's installation of VS community autofills in these 'using' statements once VS determines they're needed. Mine (Microsoft Visual Studio Community 2019 Preview, Version 16.7.0 Preview 2.0) is not so kind.
So, two questions I guess, but one or the other will likely sort me out:
Where on earth are these EPiServer namespaces documented??? For
real; I've worn Google out searching.
Alternatively, how can I get
my Visual Studio to kindly fill in the gaps, like my colleague's
does?
Thanks for any assistance. Banging my head against the wall here.
I am trying to compile code at runtime using C#, Unity and this tutorial. I've got everything running, but want to be able to use UnityEngine methods like Debug.Log(); in the pseudo-code. In order to do so, I wrote using UnityEngine; in it, but got the following error:
The type or namespace name "UnityEngine" could not be found. Are you missing an assembly reference?
How do I solve this?
I have tried adding a reference of UnityEngine to CompilerParameters.ReferencedAssemblies like this:
//parameters is of type CompilerParameters
parameters.ReferencedAssemblies.Add("UnityEngine.dll");
but that gives me the following error:
Metadata file UnityEngine.dll could not be found.
This is the most relevant part of my code, but you won't be able to reproduce it like that. Instead, get the code from the above mentioned tutorial.
public void Compile()
{
string code = #"
using UnityEngine;
namespace First
{
public class Program
{
public static void Main()
{
" + "Debug.Log(\"Test!\");" + #"
}
}
}
";
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("UnityEngine.dll");
}
Since I am inexperienced with C#, and only use it with Unity, I don't know what a .dll file is and am clueless about where to start when fixing this. I am thankful for any kind of help!
You are supposed to put the path of the UnityEngine.dll there, not just UnityEngine.dll, unless it exists in the working directory, which is highly unlikely.
According to this answer, you can easily find UnityEngine.dll (and other dlls as well) in your file system. It is under Editor\Data\Managed, so you should write:
parameters.ReferencedAssemblies.Add(#"C:\\path\to\your\unity\installation\Editor\Data\Managed\UnityEngine.dll");
I tried some of the open source solutions, but couldn't find a solution which worked on all 3 platforms. Finally I bought this asset, which works without problems on Windows, Mac and Linux: https://assetstore.unity.com/packages/tools/integration/dynamic-c-82084 The documentation and support is very good. For example I had a problem that I couldn't compile a class which uses the Unity Screen class, and the support told me that I had to include the UnityEngine.CoreModule.dll in the settings page of the asset, which solved the problem.
PS: I don't get money for this recommendation, I'm just a happy user of the asset.
Hi I want to send a photo with my telegram bot but my VS doesn't recognize "FileToSend" and my error is :
int chatId = int.Parse(dgReport.CurrentRow.Cells[0].Value.ToString());
FileStream imageFile = System.IO.File.Open(txtFilePath.Text,FileMode.Open);
bot.SendPhotoAsync(chatId, new FileToSend("1234.jpg", imageFile), txtmessage.Text);
CS0246 The type or namespace name 'FileToSend' could not be found (are
you missing a using directive or an assembly reference?)
The FileToSend() function is removed, use InputOnlineFile():
FileStream imageFile = System.IO.File.Open(txtFilePath.Text,FileMode.Open);
bot.SendPhotoAsync(chatId, new InputOnlineFile(imageFile, "image.png"), txtmessage.Text);
Sounds like you are very new to Visual Studio and also C# so I'll share a general tip. If you see a red squiggly line in Visual Studio you have a compile error. Your program will not build/run until it is fixed.
Here's my tip. Find the code that is causing the compile error (the text with a red squiggle beneath it). Right click the text and choose "Quick Actions and Refactoring". You will see several suggestions that may fix the issue.
The problem you are describing can usually be fixed using this feature. One of the options may be something like "Using Telegram.Bot;". If you choose it, it will automatically put the using statement at the top of your file and fix the compilation error. This is definitely the #1 reason I use Quick Actions and Refactoring.
Actually, the question is quite OK. I think you just might be mixing up examples you've found and tried, which - if so - is an honest mistake. The FileToSend() function is related to a (deprecated) project on GitHub at ScottRFrost/TelegramBot.
The rest of your sample seems to be mixed up a bith with, I assume, the TelegramBots/Telegram.Bot package. If you use that, the following sample might help you a bit further:
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Telegram.Bot;
using Xunit;
namespace StackOverflowSupport
{
public class Tests
{
[Fact]
public async Task SendFileWithTelegramBot()
{
// Requires NuGet package `Telegram.Bot` (v15.0.0)
var token = "YOUR_TOKEN";
using (var http = new HttpClient())
{
int chatId = 42;
var imageFile = File.Open("filepath", FileMode.Open);
var bot = new TelegramBotClient(token, http);
await bot.SendPhotoAsync(chatId, photo: imageFile, caption: "This is a Caption");
}
}
}
}
As you can see, no FileToSend() in there, which might be the cause of your problem.
Note that this is just to help you in the right direction; it is not meant as code to be used in production. Especially reading out the stream through File.Open could be improved.