Where do I find the assembly reference and how can I add it?
Error Description:
CS0234 The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.AspNetCore.Blazor.Browser' (are you missing an assembly reference?)
CS0103 The name 'RegisteredFunction' does not exist in the current context Phoneword.Client
I have a small Blazor project which I would like to run again after some time. But it seems I've deleteted the reference or something else is broken.
Edit I:
Blazor: 0.5.1
Target framework: .NET Standart 2.0
'RegisteredFunction' does not exist anymore.
This is how you define a function in a JavaScript file:
window.exampleJsFunctions = {
showPrompt: function (message) {
return prompt(message, 'Type anything here');
}
};
And this is how you call the function from your Blazor code:
using Microsoft.JSInterop;
public class ExampleJsInterop
{
public static Task<string> Prompt(string message)
{
// Implemented in exampleJsInterop.js
return JSRuntime.InvokeAsync<string>(
"exampleJsFunctions.showPrompt",
message);
}
}
Related
I'm am trying to use the provided C# MS Graph/MSAL application to create an application that utilizes the OneDrive API. I literally copy/pasted from the provided example code into my solution and I can't get the solution to build now.
I've ensured that the following NuGet packages are installed:
Microsoft.Graph
Microsoft.Identity.Client
Microsoft.Identity.Client.Desktop
Microsoft.Identity.Client.Extensions.Msal
Microsoft.Identity.Web.TokenCache
Microsoft.Windows.SDK.Contracts
I'm brand new to using MSAL and I'm sure this is just a dumb mistake on my part but any assistance would be greatly appreciated!
Error Received:
Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'Unprotect' and no accessible extension method 'Unprotect' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) Test Case Designer D:\code\Test Case Designer\TokenCacheHelper.cs 54 Active
Severity Code Description Project File Line Suppression State
Error CS1061 'object' does not contain a definition for 'Protect' and no accessible extension method 'Protect' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) Test Case Designer D:\code\Test Case Designer\TokenCacheHelper.cs 70 Active
using System.IO;
using System.Security.Cryptography;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Desktop;
using System.Windows;
using System.Security;
using Microsoft.Identity.Web.TokenCacheProviders;
using Microsoft.Identity.Client.Extensions.Msal;
namespace Test_Case_Designer
{
static class TokenCacheHelper
{
// <summary>
// Path to the token cache
// </summary>
public static string CacheFilePath { get; private set; }
public static object ProtectedData { get; private set; }
private static readonly object FileLock = new object();
private static void BeforeAccessNotification(TokenCacheNotificationArgs args)
{
lock (FileLock)
{
args.TokenCache.DeserializeMsalV3(File.Exists(CacheFilePath)
? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath),
null,
DataProtectionScope.CurrentUser)
: null);
}
}
public static void AfterAccessNotification(TokenCacheNotificationArgs args)
{
// if the access operation resulted in a cache update
if (args.HasStateChanged)
{
lock (FileLock)
{
// reflect changes in the persistent store
File.WriteAllBytes(CacheFilePath,
ProtectedData.Protect(args.TokenCache.SerializeMsalV3(),
null,
DataProtectionScope.CurrentUser)
);
}
}
}
internal static void EnableSerialization(ITokenCache tokenCache)
{
tokenCache.SetBeforeAccess(BeforeAccessNotification);
tokenCache.SetAfterAccess(AfterAccessNotification);
}
}
}
In your code, ProtectedData is defined as an object.
This should have been System.Security.Cryptography.ProtectedData
change
public static object ProtectedData { get; private set; }
to
private static ProtectedData protectedData;
public static ProtectedData GetProtectedData(){
return protectedData;
}
should fix your issue.
Edit: Changing the class name or namespace name so that the namespace and class don't have the same name doesn't fix this issue.
I have this super simple code:
Program.cs:
using System;
using CodeCleaner;
class Program
{
private static void Main(string[] args)
{
Console.WriteLine("DocTypeChecker instantiated");
var codeCleaner = new CodeCleaner.CodeCleaner();
}
}
CodeCleaner.cs:
using System;
namespace CodeCleaner
{
public class CodeCleaner
{
public CodeCleaner()
{
Console.WriteLine("CodeCleaner instantiated");
}
}
}
This produces the following error when I try to compile when I run $ csc Program.cs:
Program.cs(4,7): error CS0246: The type or namespace name 'CodeCleaner' could not be found (are you missing a using directive or an assembly reference?).
I'm definitely not missing a using directive for CodeCleaner, but what it means with assembly reference I have no idea. Other solutions on the web didn't help me in this case. Anyone know the issue here?
Running csc Program.cs won't compile CodeCleaner.cs, so your assembly will be missing the CodeCleaner class and namespace. Using csc Program.cs CodeCleaner.cs should do the trick.
Hi i'm using unity package called "Movement Animset Pro v1.693.unitypackage" for unity character moving when i import package in unity all thins goes fine except the script file it gives me errors all over the code i'm using the last unity version and here is the code
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Moves a Game Object towards a Target. Optionally sends an event when successful. Optionally set when to update, during regular update, lateUpdate or FixedUpdate. The Target can be specified as a Game Object or a world Position. If you specify both, then the Position is used as a local offset from the Object's Position.")]
public class MoveTowards2 : FsmStateAction
{
public enum UpdateType {Update,LateUpdate,FixedUpdate};
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmGameObject targetObject;
public FsmVector3 targetPosition;
public FsmBool ignoreVertical;
[HasFloatSlider(0, 20)]
public FsmFloat maxSpeed;
[HasFloatSlider(0, 5)]
public FsmFloat finishDistance;
public FsmEvent finishEvent;
public UpdateType updateType;
public override void Reset()
{
gameObject = null;
targetObject = null;
maxSpeed = 10f;
finishDistance = 1f;
finishEvent = null;
updateType = UpdateType.Update;
}
public override void OnUpdate()
{
if (updateType == UpdateType.Update)
{
DoMoveTowards();
}
}
public override void OnLateUpdate()
{
if (updateType == UpdateType.LateUpdate)
{
DoMoveTowards();
}
}
public override void OnFixedUpdate()
{
//if (updateType == UpdateType.FixedUpdate)
//{
DoMoveTowards();
//}
}
void DoMoveTowards()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
var goTarget = targetObject.Value;
if (goTarget == null && targetPosition.IsNone)
{
return;
}
Vector3 targetPos;
if (goTarget != null)
{
targetPos = !targetPosition.IsNone ?
goTarget.transform.TransformPoint(targetPosition.Value) :
goTarget.transform.position;
}
else
{
targetPos = targetPosition.Value;
}
if (ignoreVertical.Value)
{
targetPos.y = go.transform.position.y;
}
go.transform.position = Vector3.MoveTowards(go.transform.position, targetPos, maxSpeed.Value * Time.deltaTime);
var distance = (go.transform.position - targetPos).magnitude;
if (distance < finishDistance.Value)
{
Fsm.Event(finishEvent);
Finish();
}
}
}
}
and here is the errors
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(11,30): error CS0246: The type or namespace name 'FsmStateAction' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(9,3): error CS0246: The type or namespace name 'ActionCategoryAttribute' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(9,3): error CS0246: The type or namespace name 'ActionCategory' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(9,18): error CS0103: The name 'ActionCategory' does not exist in the current context
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(10,3): error CS0592: Attribute 'Tooltip' is not valid on this declaration type. It is only valid on 'field' declarations.
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(35,24): error CS0115: 'MoveTowards2.Reset()': no suitable method found to override
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(45,24): error CS0115: 'MoveTowards2.OnUpdate()': no suitable method found to override
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(53,24): error CS0115: 'MoveTowards2.OnLateUpdate()': no suitable method found to override
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(61,24): error CS0115: 'MoveTowards2.OnFixedUpdate()': no suitable method found to override
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(15,4): error CS0246: The type or namespace name 'RequiredFieldAttribute' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(15,4): error CS0246: The type or namespace name 'RequiredField' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(16,10): error CS0246: The type or namespace name 'FsmOwnerDefault' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(18,10): error CS0246: The type or namespace name 'FsmGameObject' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(20,10): error CS0246: The type or namespace name 'FsmVector3' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(22,10): error CS0246: The type or namespace name 'FsmBool' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(24,4): error CS0246: The type or namespace name 'HasFloatSliderAttribute' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(24,4): error CS0246: The type or namespace name 'HasFloatSlider' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(25,10): error CS0246: The type or namespace name 'FsmFloat' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(27,4): error CS0246: The type or namespace name 'HasFloatSliderAttribute' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(27,4): error CS0246: The type or namespace name 'HasFloatSlider' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(28,10): error CS0246: The type or namespace name 'FsmFloat' could not be found (are you missing a using directive or an assembly reference?)
Assets\MovementAnimsetPro\PlayMakerAdditionalActions\PlayMaker\Actions\MoveTowards2.cs(30,10): error CS0246: The type or namespace name 'FsmEvent' could not be found (are you missing a using directive or an assembly reference?)
and there is 5 anothe scripts with the same errors .. please help
As the error says the program doesn't find the names like 'FsmStateAction', look into your assets for that name and find the script that contains it, then put the namespace of the script at the top of your code like:
using someNamespace;
I can see that you have some errors of override, you cannot override this methods if they aren't virtual, check the code of the package before you make your own.
I'm following this Xamarin tutorial. Visual Studio throws an error when I use the "Context" class in my Android project. Shouldn't this class be included in my Android app by default?
Also, I defined an interface named "IStreamLoader" in a Portable Class Library called "Portable", and added a reference to "Portable" in my Android project. But referencing "IStreamLoader" in my Android project throws another error.
Are these two errors related?
Errors
CS0246 The type or namespace name 'IStreamLoader' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Context' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Context' could not be found (are you missing a using directive or an assembly reference?)
MyTunes.Droid\MainActivity.cs
using System.Linq;
using Android.App;
using Android.OS;
namespace MyTunes
{
[Activity(Label = "My Tunes", MainLauncher = true)]
public class MainActivity : ListActivity
{
protected async override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var data = await SongLoader.Load();
ListAdapter = new ListAdapter<Song>() {
DataSource = data.ToList(),
TextProc = s => s.Name,
DetailTextProc = s => s.Artist + " - " + s.Album
};
}
}
public class StreamLoader : IStreamLoader
{
private readonly Context context;
public StreamLoader(Context context)
{
this.context = context;
}
public Stream GetStreamForFilename(string filename)
{
return context.Assets.Open(filename);
}
}
}
Portable\IStreamLoader.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Portable
{
public interface IStreamLoader
{
System.IO.Stream GetStreamForFilename(string filename);
}
}
Try this :
using Android.Content;
I have this class:
using System;
using System.Web.Mvc;
using System.Data;
using BLL;
namespace LicenseManager.Controllers
{
public class ValidationController : BaseController
{
public ActionResult Default()
{
return View("Default");
}
[HttpPost]
public JsonResult ClearInstallation(FormCollection form)
{
var jr = new JsonResult();
try
{
var licMgr = new BLL.LicManager();
licMgr.ClearInstall(form["regKey"], form["checkKey"]);
}
catch (Exception exc)
{
jr = Json(new { success = "false", error = exc.Message });
}
return jr;
}
}
}
When I try to rebuild or debug I receive the error: The type of namespace name 'BLL' could not be found (are you missing a using directive or an assembly reference?)
I can see that it is referenced:
The intellisense works, and I don't have any errors, until I try to rebuild or compile. I know it exists, and it finds it for intellisense purposes, so why won't it allow me to rebuild or compile?
I have tried:
cleaning the solution
rebuilding
clearing the reference and re-adding it
What else can I try?
UPDATE
If you get this error, make sure you read the output. It contained the solution for me.
I had a similar problem when the referenced project was using a different .net framework. Make sure the project you are building and the project you have referenced are using the same framework.
You can verify/change the framework in properties/application/target framework