I have stumbled upon interesting problem which is destroying me last couple of hours. I have project in VS, in references I have library Communication.dll, which contains class Service.
I am invoking following method:
public void ConnectPipe()
{
Service service = new Service();
service.ConnectionMode = ConnectionModes.PIPE;
service.Connect();
}
when I run it, on second line I get MissingMethodException - Method not found: 'Void Service.set_ConnectionMode()'
when I press F12 on service class, I get the Assembly info for the class. When I look for my property, setter is in place, so it does not look like problem with referenced library:
public ConnectionModes ConnectionMode { get; set; }
has anyone any idea where problem might be please?
Had the same issue. Fixed by updating reference to the library.
Point to the exact file on the local, through button "Browse..." don't choose from the library list in references manager - that doesn't work correctly sometimes.
And rebuild the referenced assembly.
Related
I'm developing a modular blazor application (5.0.2) using VS 2019 (16.8.4), which is structured as follows:
a "Main" Solution, which consists of
RCL
Wasm project to startup the application
several "Sub" solutions which reference the Main RCL (Base components, etc) which consist of
.net5 libraries (Models, Web-service access, etc)
RCL with components, referencing the .net5 libraries (via project reference)
All projects have a post-build event to copy the DLL and PDB files to a certain path, e.g. D:\TMP.
The SubSolution references the MainRCL library via this path.
The Main Wasm project references the SubRCL library also via this path (for adding services at startup/Program.cs).
The MainRCL does not have a reference to SubRCL (components are rendered via reflection/BuildRenderTree() according to configurable UI definition).
Debugging the Main Solution worked perfectly (IIS Express/Application Debugging).
Then I tried to debug the SubModules -> I started debugging from the MainSolution and opened files from the SubModules projects in this VS instance.
At some libraries, debugging was working, but not for the SubRCL ("Unbound Breakpoint"). Then I was able to reproduce the (very strange) issue with sample solutions:
The "MainRCL" provides 2 Attributes:
[AttributeUsage(AttributeTargets.Class)]
public sealed class TestNoEnumAttribute : Attribute
{
public string Name { get; set; }
public string Mode { get; set; }
public TestNoEnumAttribute(string name, string mode)
{
Name = name;
Mode = mode;
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class TestEnumAttribute : Attribute
{
public string Name { get; set; }
public EventExecutionMode Mode { get; set; }
public TestEnumAttribute(string name, EventExecutionMode mode)
{
Name = name;
Mode = mode;
}
}
public enum EventExecutionMode
{
AutomaticAll = 0,
ManualConfiguration = 2
}
The SubRCL uses these attributes at a test-method:
[TestNoEnum("Test", "EventExecutionMode.ManualConfiguration")]
//[TestEnum("Test", EventExecutionMode.ManualConfiguration)]
public class Module1Test
{
public int IncreaseNum(int num)
{
var x = new Part1();
var part1Num = x.DoStuff(num);
var newNum = part1Num + 1;
return newNum;
}
}
The class "Part1()" which is called, is located at another library of the SubSolution
The breakpoint at the "DoStuff()" method in Part1 class is always hit (in separate .net5 library).
The breakpoint at the "IncreaseNum()" method is only called when the [TestEnum] attribute is NOT used.
As soon as the [TestEnum] attribute is used, there is an "Unbound Breapoint"; the breakpoint in "DoStuff()" method in another library is still hit.
Then I tried to "add existing project" to SubSolution and added the MainWasm project and started debugging directly from SubSolution -> same behavior.
Is there anything I oversee (e.g. regarding DLL-references or PDB file copy)?
This is already my second approach of trying to debug these modular-structured solutions - first I tried to debug via IIS (How to debug Blazor Webassembly on IIS with VS by attaching to Chrome?), but this was also not successful.
Found out there is an issue with debugging when using attribues with enum parameters:
https://github.com/dotnet/aspnetcore/issues/25380
-> I replaced the enum parameters and debugging is working fine now - Didn't get any feedback when this will be fixed so far
I had the same issue with my Blazor WASM not able to be debugged in VS due to 'Unbound breakpoint'. I have multiple projects running under the same solution and while initially the debugging worked for the WASM, it stopped after a while.
Eventually I was able to find a work around by waiting until all projects loaded and then I could disable the 'Unbound' breakpoint and re-select it. It then worked as expected.
It's not an ideal solution (especially if you have multiple breakpoints while troubleshooting) but it is workable.
I had this problem in .NET 6 and Visual Studio 2022.
I made a codebehind-file component.razor.cs but I also had code in the razor-file itself. Moving the code to the codebehind-file solved the issue and enabled the breakpoints.
Here's the scenario.
I created a brand new Asp.Net DNX RC2 Final project. I also added a .Net class library project to my solution (both under FX 4.6.1). The class library project is located in the src folder.
Then, I add a reference to the class library, and it can successfully restore all packages after making changes to the project.json file.
I've added a simple foo function to my class library
namespace ClassLibrary1
{
public class Class1
{
public static string Foo()
{
return "Bar";
}
}
}
and finally in my Home/Index view, I have added the following on top
<div>
#(ClassLibrary1.Class1.Foo())
</div>
The solution compiles with no errors.
You may think so far so good, let's continue.
Then, when I run the solution, the following is shows:
At runtime, my class library is not available.
I ran into a similar situation. In my case I got a RazorEngine exception in Visual Studio which at least gave me an indication of what was going on (it was something like a missing reference exception, even though the class library was added as a reference).
The only way that I could get it working (I'm hoping there is a better way), was to add the following code to my ConfigureServices method in Startup.cs:
services.Configure<RazorViewEngineOptions>(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = (context) =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(MetadataReference.CreateFromFile(typeof(ClassLibrary1.Class1).Assembly.Location));
};
});
I got the idea from the following websites:
Callback on RazorViewEngineOptions
Configure RazorViewEngine
I did confirm that your example is working when I add the code mentioned above.
I have a ASP.NET 5 , MVC 6 project which has reference to a CL in the same solution.
When I try to debug I am unable to enter to the CL's breakpoints.
When I come to the function calling the CL and hit F11 it just continues , so it doesn't enter into the function for debug.
When I debug and get over to the function of the CL and choose "Step into specific" and choose the function it says :
Microsoft.AspNet.Mvc.Core.pdb not loaded.
Microsoft.AspNet.Mvc.Core.pdb contains the debug information required to find the source for the module Microsoft.AspNet.Mvc.Core.dll
Module Information
Version : 6.00.0.10417
Original Location : <path in local disk>
Try one of the following options :
Change existing PDB and binary search paths and retry:
Microsoft Symbbol Servers
So when I try to get it load from microsoft symbol server it says :
Microsoft.AspNet.Mvc.Core.pdb could not be found in the selected paths
My main project is in MVC 6 and my dll is target framework : .Net 4.5.2
I think that due to the beta nature the pdb files are not on the symbol servers. I would assume that after RTM (remember VS is RC but asp.net 5 is very much still beta) they would be added to the symbol servers.
If you need support before that you can clone the asp.net MVC repository (https://github.com/aspnet/Mvc.git) to a location outside your project. Then in the global.json (solution level file) add that path to the project property. This will instruct the compiler to look there for dependency resolution. The compiler will always attempt to resolve dependency using local source over nuget package. In Visual Studio right click on references > restore packages. You should see the package icon change to indicate source. Then you can simply build, and step directly into the source.
This error can be occurred because of a wrong doing in code. I got this error once where I was implementing a base class and overriding its method without a base method call where my db context was initialized. But in my controller I was trying to use the db context which is still not initialized which caused a null reference error. Once I fixed it this error disappeared.
public class MyController : BaseController
{
private MyService _myService;
protected override void Initialize(RequestContext requestContext)
{
//I missed the base call here
//base.Initialize(requestContext);
_myService = new MyService(myDbContext);
}
}
public class BaseController : Controller
{
public MyDbContext myDbContext { get; set; }
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
myDbContext = HttpContext.GetOwinContext().Get<MongoDbContext>();
}
}
Try deleting the bin folder and rebuilding the solution.
I am trying to create a Xamarin Java Binding to the Spotify Android SDK. The SDK is now separated into two parts, one for authentication and one for the player. The former java binding works, however, the seconds gives me an error.
The original question was asked on the Xamarin Forums.
Hi,
I am trying to create a binding project for the Spotify Android SDK.
The SDK is seperated into two .aar files. One for authentication and one for media playback (Player).
Firstly I tried having both .aar files in one Binding Project, but the Player.aar was ignored. However, moving it to its own seem to work.
Now, my issue is related to the Java Interface NativePlayerNotificationCallback which is generated to IPlayerNotificationCallback (hence the lack og Notification), but in the Player class it tried to implement: global::Com.Spotify.Android.Player.INativePlayerNotificationCallback.
I can find no other mention of INativePlayerNotificationCallback in the decompiled files. Only IPlayerNotificationCallback.
I understand that this is a bit difficult to imagine. Here are the java class files seen in JD-GUI:
The generated files are listed here:
Inside the file Com.Spotify.Sdk.Android.Player.IPlayerNotificationCallback.cs:
And the error message itself
Error CS0234: The type or namespace name INativePlayerNotificationCallback' does not exist in the namespaceCom.Spotify.Sdk.Android.Player'. Are you missing an assembly reference?
I would really appreciate any insight as to how I can get this to work. It looks to me like there are some inconsistencies in the naming of the interface, but I am not sure.
Thank you for helping out,
Fredrik
Should be fixed by adding metadata to Player binding project:
<metadata>
<attr path="/api/package[#name='com.spotify.sdk.android.player']/interface[#name='NativePlayerNotificationCallback']" name="visibility">public</attr>
</metadata>
and Player class extension (into the Additions directory):
using System.Collections;
using Java.Lang;
using Java.Util.Concurrent;
namespace Com.Spotify.Sdk.Android.Player
{
public partial class Player
{
public IList InvokeAll(ICollection tasks)
{
return null;
}
public IList InvokeAll(ICollection tasks, long timeout, TimeUnit unit)
{
return null;
}
public Object InvokeAny(ICollection tasks)
{
return null;
}
public Object InvokeAny(ICollection tasks, long timeout, TimeUnit unit)
{
return null;
}
}
}
You will probably need to implement these methods correctly by calling generic methods.
Also I had to add metadata to Auth library binding project (I found it in your old topics) and referenced Auth project from Player project as it uses some of the classes (maybe that's no necessary).
I'm trying to adjust my WP8 project from self made MVVM implementation to MVVM Light.
The application compiles without errors, but when I open my MainPage.xaml in Expression Blend, I will get this error:
Class project.Services.INavigationService is already registered. App.xaml
My ViewModelLocator.cs:
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
}
else
{
if (!SimpleIoc.Default.IsRegistered<INavigationService>())
{
SimpleIoc.Default.Register<INavigationService>(() => new NavigationService());
}
}
SimpleIoc.Default.Register<MainPage>();
SimpleIoc.Default.Register<SettingsEditViewModel>();
}
As you can see from my code comment, I've already tried the fix supposed here, but I'm still getting this error in Blend. There is no other place left where I could register the INavigationService, so what could be the problem?
Any ideas? :)
I had the same issue, and this seems to be a Visual Studio issue in combination with XAML-Designer, Static Factories/Locators and Design-Time creation of objects. However: The solutions were the following:
Register without a factory (not recommended)
SimpleIoc.Default.Register<INavigationService>();
Or if you want to use a factory, unregister before registering the factory
SimpleIoc.Default.Unregister<INavigationService>();
SimpleIoc.Default.Register<INavigationService>(() => new NavigationService());
Prevent the ViewModelLocator from being created more than once by the designer/Blend by making the constructor static
static ViewModelLocator() { ... }
The error is cumbersome but could happen in this scenario: You create objects during design-time (the ViewModelLocator within App.xaml probably) and whenever you change something in your Code, the Compiler is triggered and the ViewModelLocator gets re-created without ever unregistering the services. Therefore it will complain that in the factory has already been registered. In theory, when registering classes without factories multiple times, there should be an error as-well.
Might already be solved by now, but I think you can just solve the issue in your example case by not using the factory method override.
SimpleIoc.Default.Register<INavigationService, NavigationService>();
If you do need a factory method, then you can mix this line in with your factory method approach using the design mode check like you have been.
if (ViewModelBase.IsInDesignModeStatic)
{
SimpleIoc.Default.Register<INavigationService, NavigationService>();
}
else
{
SimpleIoc.Default.Register<INavigationService>(CreateNavigationService);
}
This seems like a super old question, but after hours of googling, this is the only question that's similar to my problem, so answering here for other people.
Make sure that you have IsDataSource on your ViewModelLocator:
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
That solved my problem and my design data popped up straightaway.
Weirdly, after putting that on, all my "INavigationService is already registered" errors goes away!
Not sure why, but I only get this error when my xaml designer window is open. When I compile with it closed, the error goes away and the project is built and runs successfully.