-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' #358
Comments
Any news? Am I doing something wrong here? |
+1 on this, getting around 500 exceptions thrown on generation of a column chart in a .NET 7 application. |
just to clarify, you are on .NET 7, but not using the native C# bindings? does the error persist then when using the C# bindings instead? |
No, i don't see anything directly wrong with your code, however i do not plan to add fixes specifically targeting .NET framework stuff, so my main goal here would be first identifying if this is happening with any modern .NET version first |
So i tried to reproduce your error in netfx 471 anyways, and there are some things turning red for me: trace.SetValue("x", x);
trace.SetValue("y", y); there are no Layout layout = new Layout() and the other constructor calls turn up with So after fixing those to using System;
using Microsoft.FSharp.Collections;
using Plotly.NET;
using Plotly.NET.LayoutObjects;
using static Plotly.NET.StyleParam.LinearAxisId;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "xAxis");
xAxis.SetValue("zerolinecolor", "#ffff");
xAxis.SetValue("gridcolor", "#ffff");
xAxis.SetValue("showline", true);
xAxis.SetValue("zerolinewidth", 2);
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "yAxis");
yAxis.SetValue("zerolinecolor", "#ffff");
yAxis.SetValue("gridcolor", "#ffff");
yAxis.SetValue("showline", true);
yAxis.SetValue("zerolinewidth", 2);
Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);
layout.SetValue("yaxis", yAxis);
layout.SetValue("title", "A Figure Specified by DynamicObj");
layout.SetValue("plot_bgcolor", "#e5ecf6");
layout.SetValue("showlegend", true);
Trace trace = new Trace("line");
trace.SetValue("x", xAxis);
trace.SetValue("y", yAxis);
var fig = GenericChart.Figure.create(ListModule.OfSeq(new[] { trace }), layout);
GenericChart.fromFigure(fig).Show();
}
}
} It runs without any exceptions on my machine, meaning i cannot reproduce the error with your repro instructions. Here is the <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Plotly.NET" Version="3.0.1" />
</ItemGroup>
</Project>
|
Good catch. Thanks for the help. I confirm that the trace was the culprit and that everything works fine in net471. |
I am having this same issue in a .NET 7 project using Visual Studio 2022 I have created a repo to reproduce the error: Repo The program executes successfully and outputs the expected chart file, but there is a stream of these Exceptions in the output window while it's running. |
I have the same issue, |
Sorry but i still cannot reproduce this. If i clone the provided repo, I get no such console output:
could you maybe go into detail where you see these exceptions thrown @dr124 ? |
2023-09-11.16-57-05.mp4Hi, I just cloned the same repo that you used and added some WriteLines as you can see, the program takes way too much time to generate the plot - data preparation is instant but I did some quick benchmarking and discovered that it happened only once when I used |
Thanks, so this only happens in the debugger console? I'll give it a try. Weird error - the whole fun of First google results point to something like this https://stackoverflow.com/questions/31032122/runtime-binder-exception, where that error is thrown when dynamic members are accessed that are not set on an object. However, the library only sets these values dynamically when creating objects, but never tries to access them in an unsafe way. Also, your code does not try access any of these values. A few other notes:
That is because you are downloading chromium to render an svg from the plot.
Because chromium is downloaded after the first run, it should work fast after that, so this is expected. |
Also, i think @davidpfister might have posted the thread with the solution, i just did not understand it at the time. https://stackoverflow.com/questions/5678608/why-a-microsoft-csharp-runtimebinder-runtimebinderexception-if-the-invoked-metho seems to imply that we should expose internals from |
Even if I switched to update: Additionally, in WPF app when this code is executed on button click, I get the exceptions everytime |
@dr124 sadly I can still not reproduce this. Do you have any special settings enabled for the debugger? if I execute the repo in VS the program takes a split second and no Expections are shown: PlotlyTest.-.Microsoft.Visual.Studio.2023-09-13.20-06-50.mp4 |
So I just ran |
I think it's the |
Yep, just tested with |
So now we found it 🎉 - this seems to be excepted for dynamic objects. There is also an issue on Newtonsoft.Json that points to this stack overflow post. The gist is that
So i think we can close this and just have to accept that this is weird default behavior 😆 |
Description
I' m trying to use plotly.net in a c# .NETFramework 4.7 desktop application (great job by the way!). For the record I am not using the CSharp binder (only targeting .NET6 from what I have seen since you used record struct).
Everything works fine until I display the chart using .Show(). My console is spammed with: Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll. Looks like the code cannot access the internal dynamic object.
Repro steps
Create a C# project targeting .NETFramework 4.7.1
Reference the Plot;y.Net nuget package version 3.0.1
Create a chart using
Expected behavior
No exception should be thrown.
Actual behavior
48 exceptions were thrown in that case
Known workarounds
It is known that dynamic object are internal and thus not accessible. See this thread for a lead.
Related information
The text was updated successfully, but these errors were encountered: