Converting Html to Pdf with SelectPdf ArgumentNullException - .net-5

iam new here and hope someone can help me out.
iam trying to convert a html string to a pdf version in net5. We had it running in net core 2.2 without any problems. Now we are trying to migrate everything to net5. Well the only part which is not working anymore is converting html string to pdf document.
We are using following nuget package: Select.HtmlToPdf.NetCore
As soon we try the convert the html string with "ConvertHtmlString" we get following Exception.
System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name'
here is a simple snippet to repdoruce the problem:
var htmlString = "<html><head></head><body>Test me out!</body></html>";
var converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.Letter;
converter.Options.AutoFitWidth = HtmlToPdfPageFitMode.AutoFit;
converter.Options.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
converter.Options.PdfPageOrientation = PdfPageOrientation.Landscape;
SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString);
doc.Save("C:\\Temp\\test.pdf");
doc.Close();
Thanks.
Regards Maik

Ok thx for the hint in the comment..
before i posted my question i did some standard stuff i always do before researching deeper..
Clean solution, restarted VisualStudio and so on.. nothing worked.
Ive checked my nuget packages and i had the correct one installed.
I removed the package and reinstalled it again and well it works now. Cant exactly say what the problem was but.. it works now.

Related

Swashbuckle.AspNetCore .NET 6.0 blank swagger site

I am trying to setup swagger for the product I'm developing and cannot wrap my head around it.
I started with the most basic config as described here. The swagger.json was generated correctly under https://localhost/MyWebAPI/swagger/v1/swagger.json, but when navigating to https://localhost/MyWebAPI/swagger/index.html I get a blank site. Did some digging and most of the answers were revolving around setting up SwaggerEndpoint, RoutePrefix or some uri templates but none of them worked for me so I finally did what should have done in the first place and checked code of the site itself.
It is there... The url's seems correct:
var configObject = JSON.parse('{"urls":[{"url":"v1/swagger.json","name":"MyApp v1"}],"deepLinking":false,"persistAuthorization":false,"displayOperationId":false,"defaultModelsExpandDepth":1,"defaultModelExpandDepth":1,"defaultModelRendering":"example","displayRequestDuration":false,"docExpansion":"list","showExtensions":false,"showCommonExtensions":false,"supportedSubmitMethods":["get","put","post","delete","options","head","patch","trace"],"tryItOutEnabled":false}');
var oauthConfigObject = JSON.parse('{"scopeSeparator":" ","scopes":[],"useBasicAuthenticationWithAccessCodeGrant":false,"usePkceWithAuthorizationCodeGrant":false}');
// Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
configObject.urls.forEach(function (item) {
if (item.url.startsWith("http") || item.url.startsWith("/")) return;
item.url = window.location.href.replace("index.html", item.url).split('#')[0];
});
The issue is and I kid you not the line with interceptors that is actually split into several lines and the browser wouldn't recognise it as a correct string.
Obviously I tried to pass null as the entire section, but that just brakes everything two lines later. I am in shambles...
I tried with several versions of Swashbuckle (currently using 6.5.0, but tried with some previous ones starting from 6.1.5). Any ideas how to fix it as I guess this must be generally working but there's just something weird/wrong that I'm missing.
Right... one of the most stupid things I've encountered lately. I started reading Swashbuckle source code and the only class that when serialised wouldn't get the JsonSerializerOptions as defined in Swashbuckle project is InterceptorFunctions, so it used mine... and mine would have WriteIndented set as true...

Swagger getting struck when returning Microsoft.Graph.User return type

I have a default .NET 6 WebAPI project generated by VisualStudio to which I have added Microsoft.Graph nuget package
Here is my program.cs
and finally my controller
When I run this project and try to test the Get endpoint, the swagger UI is getting struck and there is no error being thrown
If I change the return type to either dynamic or object, it works as expected. Maybe I overlooking something basic but I couldn't figure out this issue. Any help is appreciated.
You can speedup rendering for complex types like Microsoft.Graph.User by disabling syntax highlight.
app.UseSwaggerUI(config =>
{
config.ConfigObject.AdditionalItems["syntaxHighlight"] = new Dictionary<string, object>
{
["activated"] = false
};
});
With this setting UI gets stuck only for 10-15 seconds.

Xamarin.Auth - Google authentication won't open in browser

I'm trying to do authentication on my Android application using Xamarin.Auth. Some time ago, Google made the policy that you cannot do this in an embedded web view (for totally valid reasons).
I'm trying to open the account authentication page in a browser, but keep getting the embedded web view. I understand that isUsingNativeUI needs to be true in the following code:
_auth = new OAuth2Authenticator(clientId, string.Empty, scope,
new Uri(Constant.AuthorizeUrl),
new Uri(redirectUrl),
new Uri(Constant.AccessTokenUrl),
null,
isUsingNativeUI = true);
At every point in my application, this always equals true.
Elsewhere, I have code that redirects to what should be a browser:
var authenticator = Auth.GetAuthenticator();
Intent intent = authenticator.GetUI(this);
this.StartActivity(intent);
Regardless, I keep getting a dreaded 403 disallowed_useragent error whenever I try to run the project. Is there another element to this that I'm missing?
To my knowledge, setting auth.IsUsingNativeUI = true in the constructor should dictate that it must open in a browser. I've been following this example to try and debug with no success. I even pulled the guy's repo down to my machine and ran it - the Intent variable at the moment of redirection is almost identical.
Could there be something stupid that I'm missing? What else might be going wrong?
I realize this is an old question, but I had the same issue.
You have to install version 1.5.0.3 of the Xamarin.Auth Nuget package. The newest one (version 1.7.0 right now) doesn't work. You'll have to also install the PCLCrypto nuget package in order to get that version to work.

Can't call Web api from Xamarin

I'm trying to make a simple web api call using HttpClient in an iOS build. When setting the client.BaseAddress, the BaseAddress always ends up null. I can't find what could possibly be wrong.
using System.Net.Http;
....
private const string BaseApiUrl = "http://localhost:55904/";
static HttpClient client = new HttpClient();
client.BaseAddress = new Uri(BaseApiUrl);
// client.BaseAddress is still null
I downloaded a sample non-Xamarin project and the same code works fine.
Any ideas?
Update
As I continue messing with this I figured I would try some of the other platforms. UWP seems to work fine. I was going to test Android but all of a sudden, I have a bunch of "The name 'InitializeComponent' does not exist in the current context" errors.
I'm new to Xamarin but not to VS or C#.
Update
I was just thinking, does iOS need to request any special permission for internet access? If so, where would that be set?
Just in case anyone else comes across this problem, I found the cause. It turns out that the iOS project didn't include a reference to System.Net.Http. Once I added the reference, everything worked fine.

Installing an editor plugin in web2py app

I am trying to install an editor plugin "ck-editor4" in my web2py app, following the steps at:
http://www.web2pyslices.com/slice/show/1952/ck-editor4-plugin
and
https://bitbucket.org/PhreeStyle/web2py_ckeditor/wiki/Home
I wrote the given piece of code in my application's "model/db1.y" and "views/default/index.html" as directed in the above links, but things are not working correct. I am a newbie in web2py. Please help me installing an editor (preferably which supports programming languages) in detailed steps. Thanks!
This worked for me:
in db.py:
from plugin_ckeditor import CKEditor
ckeditor = CKEditor(db)
db.define_table('wpage',
Field('title'),
Field('body', 'text',widget=ckeditor.widget),
auth.signature, # created_on, created_by, modified_on, modified_by, is_active
format='%(title)s')
In default.py:
#
auth.requires_login()
def create():
"""creates a new empty wiki page"""
ckeditor.define_tables()
form = SQLFORM(db.wpage).process(next=URL('index'))
return dict(form=form)
I used ckeditor.define_tables() in edit() and show() too. Now in show.html, display the formatting using:
{{=XML(page.body,sanitize=False)}}
This is all explained in the links in your post and
https://github.com/timrichardson/web2py_ckeditor4
By the way, I found a simple way to install an editor for web2py app. This is not ck-editor4 plugin but NicEdit. Just two lines of javascript code will do the job. Following link came as rescue to me.
http://nicedit.com/
Just follow the simple steps in "Quick Start Guide" right hand side. Create a textarea and your work is done.

Resources